SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

PHP array length or size count

Array is very flexible and any time we can add element to array  or remove element from an array. So we must know what are the present number of elements in an array. To know the total length or total element in an array we have to use count command.

We will first create an array like this

$array = array  ("ABC","DEF", "GHI", "KLM");

Now we will use the count command to know the number of elements in this array.

print count($array);


This will output 4 as there are four elements inside the array.

You can use sizeof function also to determine the number of values

$value= array(2,5,6,8,9);
echo "size of array = ".sizeof($value)."<br>"; // Output = 5

The above line output will be 5

We can findout the sum of the elements of an array by using array_sum() function

In ASP UBound function is used to get the size of an array

Further readings
 PHP array
array : Creating an Array
array_diff Difference of two arrays
array_count_values counting the frequency of values inside an array
count : sizeof Array Size or length
array_push : Adding element to an Array
array_sum : Array Sum of all elements
Displaying the elements of an array
Array checkbox
in_array : IN Array to search for elements inside an array
array_rand : Random elements of Array
array_unique : Array Unique values
Breaking of strings to create array using split command
Session Array to maintain data in different pages
unset : Deleting elements of an array by using its key or value
sort: Simple sorting of PHP array
rsort: Reverse sorting of PHP array
asort: Maintaining index of the elements after sorting
arsort: Sorting in reverse order for a PHP array
ksort: Array key Sorting in PHP
krsort: Array reverse key Sorting in PHP
usort: Sorting array by using user defined function























owaispathan14-12-2008
i m confused about one thing ... plz help me out

i am using an array for displaying the records in a loop. but i need to count an array printing the same value of records (means how many times the same value is being printed by the array)...

is there any particular way to do so ?
smo20-12-2008
You can use array_count_values function for this. There is a link to this tutorial inside Further readings section.
anant07-02-2009
can i use this function i my tpl files

<input type='text' value='sizeof($MLSColl)' id='t1'>
smo07-02-2009
If any PHP code is getting executed inside tpl file then this will also work.
Sujoy09-02-2009
count array size of array of array ??
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked
 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorials
Array Functions
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.