search
Homephp教程php手册PHP 二维数组和三维数组的过滤,php二维数组数组

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

Jun 13, 2016 am 08:44 AM
phpthree dimensionalTwo-dimensional arrayarrayfilter

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

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

<&#63;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三维数组变二维数组

<&#63;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 class="brush:php;toolbar:false">';
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 class="brush:php;toolbar:false">';
print_r($arr2);
&#63;>

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

您可能感兴趣的文章:

  • 改写函数实现PHP二维/三维数组转字符串
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.