<?php Tutorial
$arr =array (
0=>array (' title ' => ' News 1 ', ' Viewnum ' => 123, ' content ' => ' ZAQXSWEDCRFV '),
1=>array (' title ' => ' News 2 ', ' Viewnum ' =>, ' content ' => ' qwertyuiopzxcvbnm ')
);
?>
If you want to count the length of the array $arr, which means that the two-dimensional array is only two news, the number you want is 2, but if you use the different versions of PHP with Count ($arr), the results are not the same;
Later found in the PHP manual, the Count function also has a second argument, which is explained as follows:
The Count function has two parameters:
0 (or Count_normal) is the default and does not detect multidimensional arrays (arrays in an array);
1 (or count_recursive) to detect multidimensional arrays,
So if you want to determine whether the read array $arr has news information, it should be written:
<?php
if (Is_array ($arr) && count ($arr, count_normal) >0)
{
.....
} else {
.....
}
?>
You can use this code to test the function:
<?php
$arr =array (
0=>array (' title ' => ' News 1 ', ' Viewnum ' => 123, ' content ' => ' ZAQXSWEDCRFV '),
1=>array (' title ' => ' News 2 ', ' Viewnum ' =>, ' content ' => ' qwertyuiopzxcvbnm ')
);
Echo ' does not count multidimensional arrays: '. Count ($arr, 0);//count ($arr, Count_normal)
echo "<br/>";
Echo ' statistical multidimensional array: '. Count ($arr, 1);//count ($arr, count_recursive)
?>
OK, so far, I've solved the problem of getting the first dimensional length of two-dimensional or multidimensional arrays in PHP!