sizeof() function in PHP || PHP sizeof function
×


sizeof() function in php

1941

PHP sizeof() function is used to returns the number of items in a PHP array. It is an inbuilt function of PHP. The working of this function is the same as the working of count() function.

Syntax:

sizeof($array, $mode);

here,

1) $array() is a PHP array. It is mandatory.

2) $mode represents the mode of counting. It is optional. It has two possible values.

  • 0: by default it is selected. In this mode, the function does not consider the items of multidimensional arrays.
  • 1: in this mode, the function also counts the items of multidimensional arrays.

Example 1:

<?php
$arr1 = array(1,2,3,4,5,6,7,8,9);
$size=sizeof($arr1);
echo "Size of array is $size";
?>

Output:


Example 2:

<?php
$arr1 = array("FRUIT1"=>"apple","FRUIT2"=>"orange","FRUIT3"=>"fig","FRUIT4"=>"banana");
$size=sizeof($arr1);
echo "There are total $size fruits in the array";
?>

Example 3:

<?php
// sizeof() function with mode 0
$arr1 = array("FRUIT1"=>"apple","FRUIT2"=>"orange","FRUIT3"=>"fig","FRUIT4"=>"banana","OTHER FRUITS"=>array("pineapple","guava","pear"));
$size=sizeof($arr1,0);
echo "There are total $size fruits in the array";
?>


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments