A _php example of the filtering of two-dimensional PHP arrays and three-dimensional arrays

Source: Internet
Author: User
Tags arrays

Nonsense not much said, directly to everyone to paste code, the specific code as follows:

<?php
$arr = [
[,,,,],
[,,,,]
];
$arr = [
' list ' => [
[,,,],
[,,,],
[,,,]
;
] $arr = [
' list ' => [
[,,,],
[,,,],
[,,,]
]
];
$res = Array_map (function ($arr) {return
array_filter ($arr, function ($v) {return
$v!==;}
);
ARR);
$res = Array_map (function ($val) {return
array_filter ($val, function ($v) {return
!in_array (, $v);
});
}, $arr);
$res = [];
Array_walk ($arr, function ($val, $key) use (& $res) {
$res [$key] = Array_filter ($val, function ($v) {
return !in_array (, $v);
});
Var_dump ($res);
Var_dump ($res);

The following section of code to introduce PHP three-dimensional array variable two-dimensional array

<?php
$result = Array (0 => array (0 => array (bid => 41,brealname => ' We Instructors ', CID => 41,crealname ' We Instructors '),
1 => Array (0 => array (bid => 6,brealname => ' Nothing ', cid => 19,crealname ' Zhang Fish '))
;
The original array
print_r ($result);
echo "<br/>";
The first method:
foreach ($result as $key => $v) {
$new _arr[]= $v [0];
}
Echo ' <pre> ';
Print_r ($new _arr);
The second method
//initialization of $ARR2 
$arr 2=array (); 
Loop traversal three-dimensional array $arr3 
foreach ($result as $value) { 
foreach ($value as $v) { 
$arr 2[]= $v; 
} 
}
Destruction of $arr3 
unset ($result, $value, $v);
echo "<br/s>";
echo "The second method:";
Echo ' <pre> ';
Print_r ($arr 2);
? >

About PHP two-dimensional array and three-dimensional array of filtering small series to introduce so many people, I hope to help you!

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.