时间:2021-07-01 10:21:17 帮助过:16人阅读
$a = array(
array('a' => 0, 'b'=> ''),
array('a' => 0, 'b'=> ''),
array('a' => 1, 'b'=> '2'),
);
print_r(array_values(array_no_empty($a)));
function array_no_empty($arr) {
if (is_array($arr)) {
foreach ( $arr as $k => $v ) {
if (empty($v)) unset($arr[$k]);
elseif (is_array($v)) {
$arr[$k] = array_no_empty($v);
}
}
}
return $arr;
}
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => Array
(
[a] => 1
[b] => 2
)
)
$a = array(
array('a' => 0, 'b'=> ''),
array('a' => 0, 'b'=> ''),
array('a' => 1, 'b'=> '2'),
);
print_r(array_no_empty($a));
function array_no_empty($arr) {
if (is_array($arr)) {
foreach ( $arr as $k => $v ) {
if (empty($v)) unset($arr[$k]);
elseif (is_array($v)) {
$t = array_no_empty($v);
if($t) $arr[$k] = $t;
else unset($arr[$k]);
}
}
}
return $arr;
}
Array
(
[2] => Array
(
[a] => 1
[b] => 2
)
)
$a = array(
array('a' => 0, 'b'=> ''),
array('a' => 0, 'b'=> ''),
array('a' => 1, 'b'=> '2'),
);
print_r(array_values(array_no_empty($a)));
function array_no_empty($arr) {
if (is_array($arr)) {
foreach ( $arr as $k => $v ) {
if (empty($v)) unset($arr[$k]);
elseif (is_array($v)) {
$t = array_no_empty($v);
if($t) $arr[$k] = $t;
else unset($arr[$k]);
}
}
}
return $arr;
}
Array
(
[0] => Array
(
[a] => 1
[b] => 2
)
)