How to use the PHP function count () to obtain the length of the array. Intcount (mixedvar) returns the number of units in var, usually an array (only one unit for any other type ). If var is not an array type, 1 is returned.Int count (mixed var)
Returns the number of units in var, usually an array (only one unit is available for any other type ).
If var is not of the array type, the result of 1 (exception: count (NULL) is 0) is returned ).
Warning
The PHP function count () returns 0 for uninitialized variables, but 0 for empty arrays. Use isset () to test whether the variable has been initialized.
Example 1. count () example
- php
- $vegetables[0] = "corn";
- $vegetables[1] = "broccoli";
- $vegetables[2] = "zucchini";
- $text = implode(",", $vegetables);
- echo $text;
- ?>
Sometimes, if you do not know the PHP function count (), use the stupid method: select count (*) from table
Counts int count (mixed var) returns the number of units in var, usually an array (only one unit for any other type ). If var is not an array type, 1 is returned (...