PHP array length


Home - Tutorials - Basics

Get php array length. In this tutorial I will show you how to determine the length and / or the size of a PHP array. You will learn the most important methods how to use PHP functions to get length, size and memory used by the array information.

Tutorial info:


Name:PHP array length
Total steps:1
Category:Basics
Date:2007-06-21
Product:See complete product

Bookmark PHP array length



AddThis Social Bookmark Button

Step 1 - Determine PHP array length


PHP array length


As the number of elements can change time to time in your code it is important to get the actual length / size of the array. You have more option to get this information. PHP has 2 built in functions and both returns with the number of element in the array.

The first one is the count() function which counts elements in an array. You can use it like this:

Code:
  1. $colorList = array("apple"=>"red",
  2. "grass"=>"green",
  3. "sky"=>"blue",
  4. "night"=>"black",
  5. "wall"=>"white");
  6.  
  7. echo "Array size with count: ".count($colorList);
  8.  
The second function is the sizeof(). However sizeof() is only an alias of the count() so you can use it similar to count() the get the array length.







Tags: php array length, array length, array size, php array size, php, array, length, size

PHP array length - Table of contents
Step 1 - Determine PHP array length

F1 Site Family
AJAX F1
CSS F1
Database F1
Forex F1
Flash F1
HTML F1
Java F1
JavaScript F1
PhotoShop F1
PHP F1
Windows F1
 
vpsnoc
 
MaxTutorial
Monthly mortgage payment calculator
WebFormGenerator
Forex mini accounts

Total time: 0.0209