Counting the elements in an array gives the length of the array. You can find the number of elements in an array using PHP function
In this topic I will show how you can use
count() function on the array and display the number of elements in an array. Look below code how it is used:
Here, I have an array
$languages and I am using
count() function on the array. In this case output will be 5.
Take a look at the below code, I have written it in html and PHP, I want to display output in the browser.
I am displaying the array elements first and then displaying the count. By using
count($languages) in line 20, I get the number of elements in the array. I created a folder named 'array' under xampp/htdocs. Then saved this file as
index.php under xampp/htdoc/array.
If you run this in the browser using localhost/array, you will see below output: