find the length of an array in php

To find the length of an array in PHP, you can use either the count() or sizeof() function. These functions return the number of elements in an array.

Example code:

main.php
$my_array = array('apple', 'banana', 'orange');
$array_length = count($my_array); // Using count() function
echo $array_length; // Output: 3

$other_array = array(1, 2, 3, 4, 5);
$array_size = sizeof($other_array); // Using sizeof() function
echo $array_size; // Output: 5
273 chars
8 lines

Both count() and sizeof() functions can be used interchangeably to find the length of an array in PHP.

related categories

gistlibby LogSnag