当前位置:Gxlcms > PHP教程 > PHP过滤二维数组和三维数组,php二维数组数组_PHP教程

PHP过滤二维数组和三维数组,php二维数组数组_PHP教程

时间:2021-07-01 10:21:17 帮助过:33人阅读

PHP 过滤二维数组和三维数组,php二维数组数组


 1 php
 2 
 3     $arr = [
 4         [1,3,5,7,9],
 5         [2,4,6,8,0]
 6     ];
 7     $arr2 = [
 8         'list' => [
 9             [1,3,5,7],
10             [2,4,6,8],
11             [3,2,9,0],
12         ]
13     ];
14     $arr3 = [
15         'list' => [
16             [1,3,5,7],
17             [2,4,6,8],
18             [3,2,9,0]
19         ]
20     ];
21 
22     $res = array_map(function($arr){
23         return array_filter($arr, function($v) {
24             return $v !== 5;
25         });
26     }, $arr);
27 
28     $res2 = array_map(function($val) {
29         return array_filter($val, function($v) {
30             return !in_array(6, $v);
31         });
32     }, $arr2);
33 
34     $res3 = [];
35     array_walk($arr3, function($val, $key) use(&$res3) {
36         $res3[$key] = array_filter($val, function($v) {
37             return !in_array(6, $v);
38         });
39     });
40 
41     var_dump($res2);
42     var_dump($res3);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1109848.htmlTechArticlePHP 过滤二维数组和三维数组,php二维数组数组 1 ? php 2 3 $arr = [ 4 [1,3,5,7,9], 5 [2,4,6,8,0 ] 6 ]; 7 $arr2 = [ 8 'list' = [ 9 [1,3,5,7], 10 [2,4,6,8], 11 [3,2,9,...

人气教程排行