1

How can I do deep search with array_column?

For instance, I have this array:

Array
(
    [0] => Array
        (
            [id] => 100
            [url] => Home
            [parent_id] => 0
            [children] => Array
                (
                )

        )

    [1] => Array
        (
            [id] => 101
            [url] => About
            [parent_id] => 0
            [children] => Array
                (
                    [99] => Array
                        (
                            [id] => 102
                            [url] => Group
                            [parent_id] => 101
                            [children] => Array
                                (
                                )

                        )

                )

        )

)

Code:

var_dump(array_search(102, array_column($new_items, 'id')));

result:

bool(false)

I am hoping to get:

99

Any ideas?

2
  • array_column is not recursive, it just returns the values from the top-most array. Commented Dec 22, 2017 at 19:59
  • I don't think there's a built-in function that does this, you have to write a recursive function of your own. Commented Dec 22, 2017 at 19:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.