PHP 二维数组和三维数组的过滤

时间:2022-06-19 19:07:48

废话不多说了,直接给大家贴代码了,具体代码如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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);

下面一段代码给大家介绍php三维数组二维数组

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?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>';
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>';
print_r($arr2);
?>

关于PHP 二维数组和三维数组的过滤小编就给大家介绍这么多,希望对大家有所帮助!