在多维数组中搜索

时间:2017-01-16 14:03:06

标签: php arrays multidimensional-array

我有以下父数组,并且我试图从这个父数据库中获取另一个数组中缺少的元素。需要与模块和动作进行比较才能相同。

Parent
(
[0] => Array
    (
        [label] => Masters
        [module] => masters
        [action] => unit_index
    )

[1] => Array
    (
        [label] => Appointments
        [module] => appointments
        [action] => appointment_index
    )

[2] => Array
    (
        [label] => Transactions
        [module] => transactions
        [action] => 
    )

[3] => Array
    (
        [label] => Reports
        [module] => p_reports
        [action] => ds_index
    )

我想在以下子数组

中获取Parent中缺少的项目
Array
(
[masters] => Array
    (
        [label] => Masters
        [action] => unit_index
        [module] => masters
     )

[transactions] => Array
    (
        [label] => Transactions
        [action] => 
        [module] => transactions
)
[p_reports] => Array
    (
        [label] => Reports
        [action] => ds_index
        [module] => p_reports
    )

我尝试使用in_array进行搜索,并在数组中使用递归的某些版本,但我无法使用多个键进行搜索。

1 个答案:

答案 0 :(得分:0)

check this page

PHP 4> = 4.0.5,PHP 5,PHP 7)

array_search - 在数组中搜索给定值,并在成功时返回第一个相应的键