PHP: Determine Number of Elements in an Array / Length of Array
Tip by NetGuy | 2014-05-15 at 20:18
Today, I would like to show you how to get the number of elements that are stored in an array in PHP - or, in other words, how to determine the length of an array.
For this, let us look at a small example:
$arr = array(1, 2, 3); echo count($arr); // 3
First, we are creating a new array with three elements (1/2/3). You can just use the function array() for creating a new array and parsing the desired elements. We are saving the new array in the variable $arr.
After that, we already want to specify the length of the array. For this, we can use the function count() to which we simply can pass the array variable. As expected, the result is 3.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
JavaScript: Create and Use Arrays
Info | 0 Comments
PHP: Remove all empty elements from string array
Tip | 0 Comments
MySQL: Combine full text search with LIKE search for words with 3 letters
Tutorial | 2 Comments
jQuery: Does an Element exist?
Tip | 1 Comment
Lazarus: Load File as Byte Array and save Byte Array as File
Tutorial | 0 Comments
jQuery: Count Elements, Images, Classes etc
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.