How do I check if array value is empty?

前端 未结 8 1721
天命终不由人
天命终不由人 2020-12-09 04:03

Here is my array ouput

Array
(
    [1] => 1
    [2] => 2
    [3] =>  
)

How do I know the [3] => is empty?

相关标签:
8条回答
  • 2020-12-09 04:34

    Try this:

    <?php
        $data=array(
            'title' => 'Test Name Four',
            'first_name' => '',
            'last_name' => 'M',
            'field_company' => 'ABC',
            'email' => '',
            'client_phone_number' => '',
            'address_line_1' => '',
            'address_line_2' => 'Address 3',
            'address_line_3' => '',
            'address_line_4' => '',
            'post_code' => '',
            );
        echo '<pre>';
        print_r($data);
        foreach ($data as $key => $case ) { 
            echo "$key => ".is_multiArrayEmpty($case)."<br>"; 
        }
        function is_multiArrayEmpty($multiarray) { 
            if(is_array($multiarray) and !empty($multiarray)){ 
                $tmp = array_shift($multiarray); 
                    if(!is_multiArrayEmpty($multiarray) or !is_multiArrayEmpty($tmp)){ 
                        return false; 
                    } 
                    return true; 
            } 
            if(empty($multiarray)){ 
                return true; 
            } 
            return false; 
        } 
    ?>
    
    0 讨论(0)
  • 2020-12-09 04:37

    im using in my project like this for check this array

    im posting form data like this array('username' => 'john','surname' => 'sins');

    public function checkArrayKeyExist($arr) {
        foreach ($arr as $key => $value) {
            if (!strlen($arr[$key])) {
                return false;
            }
        }
        return true;
    }
    
    0 讨论(0)
提交回复
热议问题