Multidimensional Array Key Search

I have a multidimensional array like this (Lets call it $multiar):

Array
(
    [2] => Array
        (
            [1] => 2
        )

    [3] => Array
        (
            [1] => 3
        )

    [4] => Array
        (
            [1] => 4
            [2] => 8
        )

    [6] => Array
        (
            [1] => 6
            [2] => 7
            [3] => 9
            [4] => 4
        )

    [10] => Array
        (
            [1] => 10
        )

)

I have another array like this (Lets call it $singlear):

Array
(
    [2] => dual(2)
    [3] => dual(2)
    [4] => dual(2)
    [5] => dual(2)
    [6] => dual(2)
    [7] => single(1)
    [8] => single(1)
    [9] => dual(2)
    [10] => dual(2)
)

I’d like to be able to loop through the keys in $singlear and find if the values exist in the innermost arrays of $multiar. I want to target the keys in $singlear that DO NOT exist as values in $multiar. In this example, the only one that should match the condition is 5.

Should I loop through $multiar instead and see if the values are keys in $singlear? What is most efficient? Thanks in advance!

The best answer depends on 2 things mainly.

[ol][li]How many levels will/could there be? Is it fixed, have a maximum of 2/3, or completely dynamic?[/li]
[li]How large is the array, is it a hefty array with a large amount of elements per dimension, and are the values large strings/numbers or small integers[/li][/ol]

Sponsor our Newsletter | Privacy Policy | Terms of Service