How to use sizeof in PHP

In this article, I will explain how the sizeof() function can be used in PHP.
  • 1593

sizeof() function in PHP

  • The sizeof() function is used to count the elements of an array, or the properties of an object.
  • The sizeof() function is an alias of the count() function.
  • The sizeof() function is mainly useful for counting all the elements of a multidimensional array.

Syntax

sizeof(array,mode)

Parameter

  • array array is required parameter. Determine the array or count to object.
  • mode mode is optional parameter. It's determine the mode of the function. Possible values:
    • 0 - This is the default case value. It does not detect multidimensional arrays.
    • 1 - It detects multidimensional arrays

Example

The following example show to how the sizeof() function can be used in PHP.

<html>

<body>

<h3 style="color: royalblue;">sizeof() function example in PHP</h3>

    <?php 

    $a[0] = 'Hindi'; 

    $a[1] = 'English'; 

    $a[2] = 'Math'; 

    $a[3] = 'Computer'; 

    $result = sizeof($a); 

    echo "Total element in array : " .$result; 

    ?>

</body>

</html>

 

Output

sizeofphp.jpg
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.