简体   繁体   中英

Get the value from array using laravel

This is the sample array

Array
(
    [note] => Array
        (
            [to] => Array
                (
                    [user] => Array
                        (
                            [name] => First User
                        )

                    [abc] => 123
                    [lmn] => 4582
                )

            [from] => Jani
            [heading] => Reminder
            [body] => Array
                (
                    [abc] => 123
                )

        )

)

I have a string like "note > to > abc" and want value of "abc" under "to" array. So how can I get the value?

In laravel, there is a helper method named data_get() for getting a specific key without throwing error if it doesn't exists.

It is documented here

You can use it like below:

data_get($arr, 'note.to.abc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM