How to count all elements or values in an array in PHP
Answer: Use the PHP
You can use the PHP
sizeof() function to get the number of elements or values in an array. The
sizeof() function returns 0 for a variable that has been initialized with an empty array, but it may also return 0 for a variable that isn't set.
You can use use the
isset() function to check whether a variable is set or not.
ExampleTry this code »
$days = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
// Printing array size
Here are some more FAQ related to this topic: