Home >Backend Development >PHP Tutorial >PHP filtering of two-dimensional arrays and three-dimensional arrays, php two-dimensional array array_PHP tutorial

PHP filtering of two-dimensional arrays and three-dimensional arrays, php two-dimensional array array_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 08:56:44810browse

PHP two-dimensional array and three-dimensional array filtering, PHP two-dimensional array array

No more nonsense, I will post the code directly for you. The specific code is as follows:

<&#63;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 code will introduce to you how to convert a php three-dimensional array into a two-dimensional array

<&#63;php
$result = Array(0 => Array(0 => Array(bid => 41,brealname => 'we教官',cid => 41,crealname => 'we教官')),
1 => Array(0 => Array(bid => 6,brealname => '虎子',cid => 19,crealname => '张鱼'))
);
//原数组
print_r($result);
echo "<br />";
//第一种方法:
foreach ($result as $key =>$v){
$new_arr[]=$v[0];
}
echo '<pre class="brush:php;toolbar:false">';
print_r($new_arr);
//第二种方法
//初始化$arr2 
$arr2=array(); 
//循环遍历三维数组$arr3 
foreach($result as $value){ 
foreach($value as $v){ 
$arr2[]=$v; 
} 
}
//销毁$arr3 
unset($result,$value,$v);
echo "<br /s>";
echo "第二种方法:";
echo '<pre class="brush:php;toolbar:false">';
print_r($arr2);
&#63;>

This editor will tell you so much about the filtering of two-dimensional arrays and three-dimensional arrays in PHP. I hope it will be helpful to you!

Articles you may be interested in:

  • Rewrite function to convert PHP two-dimensional/three-dimensional array to string

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111350.htmlTechArticlePHP filtering of two-dimensional arrays and three-dimensional arrays, php two-dimensional arrays. Not much nonsense, let’s give it to you directly The code is pasted. The specific code is as follows: php$arr = [[,,,,],[,,,,]];$arr = ['l...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn