Php judges the number of empty one-dimensional arrays in two-dimensional arrays without loops as far as possible.

I would like to ask php how to determine whether each one-dimensional array in a two-dimensional array is empty without using for and other loops, and count out the number of empty arrays, and find out the relevant functions in the system function.

 $a = [
        [],
        [],
        [],
        [],
        []
    ];

$b = [
    ["a" => 1],
    [],
    [],
    ["b" => 2],
    []
];

for example, how do the above two arrays give elegant answers without loops or loops?

Php
Apr.07,2021

$b = [
    ['a' => 1],
    [],
    [],
    ['b' => 2],
    []
];

// 
$tmp = array_filter($b);

echo '
';
var_dump(array_diff_key($b, $tmp));

result:

array(3) {
  [1]=> array(0) { }
  [2]=> array(0) { }
  [4]=> array(0) { }
}

these functions must still be loops inside


if you only count the number of empty spaces, the following code should be able to

$a = [
        ['a' => 1],
        [],
        [],
        [],
        []
    ];

$b = array_filter($a);

$nullnum = count($a)-count($b);

echo $nullnum;

$b = [
    ['a' => 1],
    [],
    [],
    ['b' => 2],
    []
];
array_walk($b,function ($v) use(&$num){empty($v) ? $num += 1 : '';});
var_dump($num);

json_encode? Then query the number of occurrences of the string [] ?

Menu