The default value of a two-dimensional array is empty. How to determine if it is empty and not execute the code inside the if?

WBOY
Release: 2016-07-06 13:51:13
Original
1253 people have browsed it

<code>$pet = array(["name"]=>array('','','')["age"]=>array('','',''));

if($pet){
    echo $pet
}

具体代码如上,当数组有值时,才输出。 本人用if 判断失败。</code>
Copy after login
Copy after login

Reply content:

<code>$pet = array(["name"]=>array('','','')["age"]=>array('','',''));

if($pet){
    echo $pet
}

具体代码如上,当数组有值时,才输出。 本人用if 判断失败。</code>
Copy after login
Copy after login

<code>$pet = array("name"=>array('','',''),"age"=>array('','',''));

foreach($pet as $pKey => $pVal){

    $pet[$pKey] = array_filter($pVal);
}
$pet = array_filter($pet);

if(!empty($pet)){
    var_dump($pet);
}
</code>
Copy after login

Is this the main point of the question?

1, code error,

<code>name和age是二维数组的key,之间要逗号隔开。

$pet = array(["name"]=>array('','',''),["age"]=>array('','',''));

if($pet){
    echo $pet
}
</code>
Copy after login

2. When you say "the array is output only when it has a value", does it mean $pet, or name or age.

<code>array_filter过滤一下空数组。
</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template