Ask for an empty record in a multidimensional array (a bug that was last resolved

Source: Internet
Author: User
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]);

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.