我有以下数组:
array(4) {
[29] => NULL
[31] => NULL
[33] => NULL
[35] => NULL
}
如果所有键都包含NULL值,我想测试所有键。
答案 0 :(得分:3)
if(count(array_filter($input, 'is_null')) == count($input)) {
}
应该是你要找的东西:)
答案 1 :(得分:2)
// need php version >= 5.3 or you need to define a function, or just use a loop to check.
if (!count(array_filter($your_array, function($var){return $var !== null}))) {
// all values is null.
}
答案 2 :(得分:0)
超级简单的方法:
function allNULL($array){
foreach($array as $i)
if($i!=null)
return FALSE;
return TRUE;
}
答案 3 :(得分:0)
<?php
$filternull = function( $value ) {
return $value !== null;
}
$remaining = array_filter( $yourarray, $filternull );
echo count( $remaining );
// === 0, if all were "null";
?>