使用密钥过滤多维数组



我需要那里的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
        )
)

您可以将array_filter与检查对象中存在custom_search_emp_id_11密钥的函数:

$filtered_array = array_filter($array, function ($v) { return isset($v->custom_search_emp_id_11); });

3v4l.org上的演示

最新更新