How to determine if an array has any elements or not?

后端 未结 8 2033
青春惊慌失措
青春惊慌失措 2020-12-06 09:31

How do I find if an array has one or more elements?

I need to execute a block of code where the size of the array is greater than zero.

if ($result &         


        
8条回答
  •  旧巷少年郎
    2020-12-06 10:00

    count — Count all elements in an array, or something in an object

    int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )
    

    Counts all elements in an array, or something in an object.

    Example:

    In your case, it is like:

    if (count($array) > 0)
    {
        // Execute some block of code here
    }
    

提交回复
热议问题