PHP 2D array and 3D array filtering, php 2D array _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.