PHP Array Length Examples. In this example we will see how to find the array length in a PHP program.
PHP Array Length Examples. In this example we will see how to find the array length in a PHP program.Here you will learn how you find the PHP Array Length. You can find the Array Length using the sizeof() and count() functions.
As you know, PHP is free scripting language that is similar to c and c++ as most of the concept are borrowed from it. Array is one of those features. In this article we'll talk about the Array length and the two different ways to get the size of array.
Array is quite flexible and due to this nature of array's we can do lots of manipulation with it to get different outputs, also we can add and remove elements defined within array anytime. So the function array length is used to get the actual size of array before doing any modification to it. You can get the length of array with the help of two different functions.. 1) count() and 2) sizeof(). Both the functions are same and generates same output but "sizeof()" is a alias of count function.
Example of array length in PHP
PHP array sizeof () example
<?PHP $weekdays = array(Sunday, Monday, Tuesday, Thrusday, Friday); echo "Number of weekdays = ".sizeof($weekdays); ?> |
PHP array count () example
<?PHP $weekdays = array(Sunday, Monday, Tuesday, Thrusday, Friday); echo "Number of weekdays = ".count($weekdays); ?> |
In both the example output would be the same...
Number of weekdays = 5 |
So it does not matter which function you are using as both performs the same action.