求教:在二维数组中,删除某元素的值为空的数据

array(3) {
[0] => array(1) { ["title"] => "题1" }
[1] => array(1) { ["title"] => "" }
[2] => array(1) { ["title"] => "题2" }
}

我想删除title的值为空的数据,变成如下
array(2) {
[0] => array(1) { ["title"] => "题1" }
[1] => array(1) { ["title"] => "题2" }
}

解决办法:

可以用array_filter
$s = [['title'=>'题1'],['title'=>''],['title'=>'题2']];
$s = array_filter($s, function($value) {
return !empty($value['title']);
});
var_dump($s);

转载:http://www.thinkphp.cn/topic/45793.html

----------------------------------------------------------------------------------------------------------------------------------

 

posted @ 2020-08-28 11:43  搬砖小伙子  阅读(736)  评论(0编辑  收藏  举报