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

后端 未结 8 1961
青春惊慌失措
青春惊慌失措 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:11
    <pre>
    $ii = 1;
    $arry_count = count($args);
    foreach ( $args as $post)
    {
        if( $ii == $arry_count )
        {
            $last = 'blog_last_item';
        }
        echo $last;
        $ii++; 
    }
    </pre>
    
    0 讨论(0)
  • 2020-12-06 10:19

    For those who start with the array in PHP presented it this way: more information here

    //Array
    $result = array(1,2,3,4);
    
    //Count all the elements of an array or something of an object
    if (count($result) > 0) {
        print_r($result);
    } 
    
    // Or 
    // Determines if a variable is empty
    if (!empty($result)) {
        print_r($result);
    }
    
    // Or 
    // sizeof - Alias of count ()
    if (sizeof($result)) {
        print_r($result);
    } 
    
    0 讨论(0)
提交回复
热议问题