Filters PHP two-dimensional arrays and three-dimensional arrays, and filters php two-dimensional arrays. PHP two-dimensional array and three-dimensional array filtering, php two-dimensional array is not much nonsense, directly paste code for everyone, the specific code is as follows: php $ arr [[,], [,]; $ arr [l PHP two-dimensional array and three-dimensional array filtering, php two-dimensional array
If you don't talk much about it, paste the code directly. the specific code is 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 code describes how to change php 3D arrays to 2D arrays.
<? Php $ result = Array (0 => Array (0 => Array (bid => 41, brealname => 'We instructor ', cid => 41, crealname => 'We instructor '), 1 => Array (0 => Array (bid => 6, brealname => 'Tiger sub', cid => 19, crealname => 'Zhang yu '); // original array print_r ($ result); echo"
"; // Method 1: foreach ($ result as $ key => $ v) {$ new_arr [] = $ v [0];} echo''; Print_r ($ new_arr); // method 2 // initialize $ arr2 $ arr2 = array (); // cyclically traverse 3D arrays $ arr3 foreach ($ result as $ value) {foreach ($ value as $ v) {$ arr2 [] = $ v ;}} // destroy $ arr3 unset ($ result, $ value, $ v); echo"
"; Echo" Method 2: "; echo'';print_r($arr2);?>
I would like to introduce so much to you about the filtering of PHP 2D arrays and 3D arrays. I hope it will be helpful to you!
Articles you may be interested in:
- Rewrite functions to convert PHP 2D/3D arrays to strings
Http://www.bkjia.com/PHPjc/1111350.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1111350.htmlTechArticlePHP two-dimensional array and three-dimensional array filtering, php two-dimensional array nonsense not much said, directly to everyone posted code, the specific code is as follows: php $ arr = [[,], [,]; $ arr = ['l...