Ask for an empty record in a multidimensional array (a bug that was last resolved
This post was last edited by A9925 on 2015-03-16 18:29:58
Original stickers
: http://bbs.csdn.net/topics/390997712
New question, when there is a value of ' 0 ' in the array, the element is removed, which is actually a valued element
["Status"]=>
String (1) "0"
$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;
}
How to improve this method, thank you!
------to solve the idea----------------------
if (empty ()) is changed to if ($v = = = False) {unset ...}
------to solve the idea----------------------
if (empty ($v)) unset ($arr [$k]);
Switch
if (Empty ($v)
&& $v!== 0) unset ($arr [$k]);