How PHP determines if a multidimensional array contains null values

Source: Internet
Author: User
Help! For example, if a column appears empty once, exclude this column, how to implement


Reply to discussion (solution)

Is that so??

$arr =array (' Listid ' =>array (', 5 '), ' title ' =>array (', ', '), ' type ' =>array (' ', ' I have '), ' Count ' =>array (', 3) , ' content ' =>array (' none ', ' none '), foreach ($arr as $k + $v) {if (Is_array ($v)) {foreach ($v as $v 2) {if ($v 2== ") {unset ($ arr[$k]);}}} echo "
";p Rint_r ($arr); echo"
/*array ( [content] = = Array ( [0] = = None [1] = none )) */


I don't think you mean 2 floor. Answer, your data structure is a like the article is a few articles is not all the first data is removed only left each of the second key value of a

A foreach loop array, which finds that the null value first =null the line and then unset out

3 floor is what I want to express, in the above example! is to keep the second key value, because it all has a value, how to do it?

It is recommended to post your array and the final result. and explain the principle.



Print_ ($_post);
Results:

Array
(
[Listid] = = Array
(
[0] = 1
[1] = 5
[2] = 4
)

[title] = = Array
(
[0] = =
[1] = 33
[2] = 39
)

[Type] = = Array
(
[0] = = u
[1] = = T
[2] = =
)

[Count] = Array
(
[0] = =
[1] = 7
[2] = =
)

[content] = = Array
(
[0] = = None
[1] = = None
[2] = = None
)

)

$arr =array (    ' listid '  = = Array (', 5 '),    ' title '   = = = Array (', ', ') ',    ' type '    = = Array (' , ' I have '),    ' count ' = =   Array (', 3),    ' content ' = = Array (' None ', ' none '),); $t = Call_user_func_array (' Array_ Map ', Array_merge (array (null), $arr)), foreach ($t as $k = = $v) if (Array_diff ($v, Array ("))! = $v) unset ($t [$k]); $t = Cou NT ($t) = = 1? Array_chunk (current ($t), 1): Call_user_func_array (' Array_map ', Array_merge (array (null), $t));p Rint_r (array_combine (Array_keys ($arr), $t));
Array ([    Listid] + = Array (            [0] = 5        )    [title] = = Array        (            [0]        = )    [Type] = = Array        (            [0] = = I have        )    [count]        /= Array (            [0] = 3        )    [content] = = Array        (            [0] = = none        ))

Thank you for the moderator answer! You've got the results you want.
Now, if there is not a complete set of values in the $arr, there will be an error.

Thank you, it's settled.

  • Related Article

    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.