0 0 Votes

PHP: Determine Number of Elements in an Array / Length of Array

Tip by NetGuy | 15/05/2014 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.

ReplyPositiveNegative

About the Author

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

Related Topics

JavaScript: Get Array Length
Question | 1 Answer

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 articles on askingbox.com. How to do.