How does PHP determine whether a multi-dimensional array contains null values?

Source: Internet
Author: User
How does PHP determine whether a multi-dimensional array contains null values! For example, if a column has a null value, this column is excluded. how can this problem be solved?


Reply to discussion (solution)

So ??

$ Arr = array ('listid' => array ('', 5), 'title' => array ('', 38 ), 'type' => array ('', 'I'), 'count' => array ('', 3), 'content' => array ('none ', 'none'); foreach ($ arr as $ k => $ v) {if (is_array ($ v) {foreach ($ v as $ v2) {if ($ v2 = '') {unset ($ arr [$ k]) ;}}} echo"
";print_r($arr);echo "
";/* Array ([content] => Array ([0] => None [1] => None ))*/


I think what you mean is not answered on the second floor. your data structure seems to be an article. Is it true that a few articles remove all the first data and leave only the second key value for each one?

In the foreach loop array, the row = null is first found to be null, and then unset

The third floor is what I want to express. in the above example! The second key value is retained, because all values are available. how can this problem be solved?

We recommend that you paste your array and final result. And describe how it works.



Print _ ($ _ POST );
Result:

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 ('', 38 ), 'type' => array ('', 'I'), '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 = count ($ t) = 1? Array_chunk (current ($ t), 1): call_user_func_array ('Array _ map', array_merge (array (null), $ t )); print_r (array_combine (array_keys ($ arr), $ t ));
Array ([listid] => Array ([0] => 5) [title] => Array ([0] => 38) [type] => Array ([0] => I have) [count] => Array ([0] => 3) [content] => Array ([0] => None ))

Thank you! You have obtained the desired result.
Now, if $ arr does not have a complete set of values, an error will occur.

Thank you for solving the problem.

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.