PHP array: count or sizeof?

后端 未结 8 886
慢半拍i
慢半拍i 2020-11-30 21:27

To find the number of elements in a PHP $array, which is faster/better/stronger?

count($array) or sizeof($array) ?

Ed

相关标签:
8条回答
  • 2020-11-30 22:26

    They are identical according to sizeof()

    In the absence of any reason to worry about "faster", always optimize for the human. Which makes more sense to the human reader?

    0 讨论(0)
  • 2020-11-30 22:26

    Please use count function, Here is a example how to count array in a element

    $cars = array("Volvo","BMW","Toyota");
    echo count($cars);
    

    The count() function returns the number of elements in an array.

    The sizeof() function returns the number of elements in an array.

    The sizeof() function is an alias of the count() function.

    0 讨论(0)
提交回复
热议问题