欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-03 13:51:11
...

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,...
相关标签: 多维数组