我需要那里的PHP专家的帮助。我想对此结果进行一些过滤。我想使用键custom_search_emp_id_11
对其进行过滤。希望有一个较短的/一个班轮代码/功能来做过滤器?预先感谢您的回答!
Array
(
[0] => stdClass Object
(
[custom_search_emp_id_11] => flag_emp_id_11
[custom_search] => flag_emp_id_11
[eti_id] => 1
[time] => 1:00
[emp_id] => 11
)
[1] => stdClass Object
(
[custom_search_emp_id_22] => flag_emp_id_22
[custom_search] => flag_emp_id_22
[eti_id] => 4
[time] => 1:00
[emp_id] => 22
)
[2] => stdClass Object
(
[custom_search_emp_id_33] => flag_emp_id_33
[custom_search] => flag_emp_id_33
[eti_id] => 5
[time] => 1:00
[emp_id] => 33
)
[3] => stdClass Object
(
[custom_search_emp_id_11] => flag_emp_id_11
[custom_search] => flag_emp_id_11
[eti_id] => 1
[time] => 1:00
[emp_id] => 11
)
)
,输出将是:
Array
(
[0] => stdClass Object
(
[custom_search_emp_id_11] => flag_emp_id_11
[custom_search] => flag_emp_id_11
[eti_id] => 1
[time] => 1:00
[emp_id] => 11
)
[3] => stdClass Object
(
[custom_search_emp_id_11] => flag_emp_id_11
[custom_search] => flag_emp_id_11
[eti_id] => 2
[time] => 1:00
[emp_id] => 11
)
)
答案 0 :(得分:1)
您可以将array_filter
与用于检查对象中custom_search_emp_id_11
键是否存在的功能一起使用:
$filtered_array = array_filter($array, function ($v) { return isset($v->custom_search_emp_id_11); });