<?php
$arr=[0=>"p",1=>"a",2=>"b",3=>"c",4=>"",5=>"d",6=>""];
$arr2=array(0=>"p",1=>"a",2=>"b",3=>"c",4=>"",5=>"d",6=>"");
$arr3=[0=>array(‘a‘,‘b‘),
1=>array(),
2=>array(‘c‘,‘2‘),
3=>array(),
4=>array(‘1‘,‘f‘),
5=>array(‘g‘,‘h‘),
];
echo is_array($arr2);//echo 1;
echo is_array($arr);//echo 1;
echo is_array($arr3);//echo 1;
$arrx=array_filter($arr3);//清除值为空的或者用回调函数筛选掉一些值
$arrx=array_values($arrx);//返回所有值并重新建立数字索引
print_r($arrx);
//Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [0] => c [1] => 2 ) [2] => Array ( [0] => 1 [1] => f ) [3] => Array ( [0] => g [1] => h ) )
//回调函数
function sele($arr){
if($arr[0]=="1"||$arr[1]=="2")
return false;
else
return true;
}
$arrx=array_filter($arr3,"sele");//二维数组变成空数组,并没有清除
$arrx=array_filter($arrx);//再次清除
$arrz=array_values($arrx);
print_r($arrz);
// Array ( [0] => Array ( [0] => a [1] => b ) [1] => Array ( [0] => g [1] => h ) )
原文地址:https://www.cnblogs.com/robot-s/p/9747274.html