原样
array(3) {
[0] => array(1) { ["title"] => "题1" }
[1] => array(1) { ["title"] => "" }
[2] => array(1) { ["title"] => "题2" }
}
结果
array(2) {
[0] => array(1) { ["title"] => "题1" }
[1] => array(1) { ["title"] => "题2" }
}
方式一
$a = array(
array("title" => "题1"),
array("title" => ""),
array("title" => "题2"),
);
$a = array_values(array_filter($a, function($t) { return $t['title'];}));
var_dump($a);
array(2) {
[0]=> array(1) { ["title"]=> string(3) "题1" }
[1]=> array(1) { ["title"]=> string(3) "题2" }
}
方式二:保留键
$a = array(
array("title" => "题1"),
array("title" => ""),
array("title" => "题2"),
);
for($i=0,$len=count($a); $i<$len; $i++){
if($a[$i]['title']==""){
unset($a[$i]);
}
}
print_r($a);
Array
(
[0] => Array
(
[title] => 题1
)
[2] => Array
(
[title] => 题2
)
)
网友评论