[英]Filter multi-dimensional array using key
I need help from the PHP experts there. 我需要那里的PHP专家的帮助。 I want to do some filters in this result. 我想对此结果进行一些过滤。 I want to filter it using the key custom_search_emp_id_11
. 我想使用键custom_search_emp_id_11
对其进行过滤。 hope there's a shorter/one liner code/function to do filters? 希望有一个较短的/一个班轮代码/功能来做过滤器? thank you in advance for the answers! 预先感谢您的回答!
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
)
)
and the output will be : 输出将是:
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
)
)
You can use array_filter
with a function that checks for the existence of the custom_search_emp_id_11
key in the objects: 您可以将array_filter
与用于检查对象中是否存在custom_search_emp_id_11
键的函数一起使用:
$filtered_array = array_filter($array, function ($v) { return isset($v->custom_search_emp_id_11); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.