1、 过滤或删除数组中的某个值
<?php $template_from_id_list = [ 1,2,3,'','the formId is a mock one',5 ]; $template_from_id_list = array_filter($template_from_id_list,function($v){ if($v == 'the formId is a mock one' || empty($v)){ return false; } return true; }); sort($template_from_id_list); ////重新生成索引下标 print_r($template_from_id_list); ?>
2、过滤或删除二维数组中的指定字段数组
<php $data = [ [ 'id'=>1, 'delete_status'=>2, ], [ 'id'=>2, 'delete_status'=>1, ] ]; $data = array_filter($data,function($vv){ if($vv['delete_status'] == 2){ return false; } return true; }); sort($data); print_r($data); ?>