Change language

PHP Sizeof () function

Syntax:
int sizeof (array, mode);
Parameter:This function takes two parameters as shown in the syntax above and described below:
  • array : this parameter represents an array containing the elements that we need to count.
  • mode : This is an optional parameter that defines the mode of the function. Can take two different values, as shown below:
    • 0: this is the default, ignores all elements of multidimensional arrays
    • 1: it reads the array recursively (counts all elements of multidimensional arrays)
  • Return Value:This function returns an integer value, as shown in the syntax, that represents the number of elements present in the array. Examples:
    Input: array (1,2,3,4,5,6) Output: 6 Input: array (1,2,5,6) Output: 4
    The following programs illustrate the sizeof() function in PHP:
    • Count the number of elements in a one-dimensional array: // input array $a = array (1,2,3,4,5,6); // get the total number of items // present in the array. $result = sizeof ( $a ); print ( $result ); ?> Output:
      6
    • Counting the number of elements in a multidimensional array: $array = array ( ’name’ = > array ( ’Geeks’ , ’ For’ , ’Geeks’ ), ’article’ = > array ( ’sizeof’ , ’function’ , ’ PHP’ ));  
      // recursive score echo sizeof ( $array , one); // output 8 
      // normal count echo sizeof ( $array ); // output 2 
      ?>
      Output:
      8 2
    Link:
    http://php.net/manual/en/function.sizeof.php

    Shop

    Learn programming in R: courses

    $

    Best Python online courses for 2022

    $

    Best laptop for Fortnite

    $

    Best laptop for Excel

    $

    Best laptop for Solidworks

    $

    Best laptop for Roblox

    $

    Best computer for crypto mining

    $

    Best laptop for Sims 4

    $

    Latest questions

    NUMPYNUMPY

    Common xlabel/ylabel for matplotlib subplots

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    12 answers

    NUMPYNUMPY

    Flake8: Ignore specific warning for entire file

    12 answers

    NUMPYNUMPY

    glob exclude pattern

    12 answers

    NUMPYNUMPY

    How to avoid HTTP error 429 (Too Many Requests) python

    12 answers

    NUMPYNUMPY

    Python CSV error: line contains NULL byte

    12 answers

    NUMPYNUMPY

    csv.Error: iterator should return strings, not bytes

    12 answers

    News


    Wiki

    Python | How to copy data from one Excel sheet to another

    Common xlabel/ylabel for matplotlib subplots

    Check if one list is a subset of another in Python

    sin

    How to specify multiple return types using type-hints

    exp

    Printing words vertically in Python

    exp

    Python Extract words from a given string

    Cyclic redundancy check in Python

    Finding mean, median, mode in Python without libraries

    cos

    Python add suffix / add prefix to strings in a list

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    Python - Move item to the end of the list

    Python - Print list vertically