Get a value from within an array of object in Laravel

Viewed 18929

I am quite new no laravel. I know that it is a pretty basic question. But, I still can't figure it out. Heres my Array output and I want to get the value of name from within this array. This is the output I get in postman after I used print_r:

Array
(
    [0] => Array
        (

            [name] => Test 2322              
            [id] => 4
        )

)
5 Answers

In newest version of laravel you can use the Arr::pluck() helper function to take an array of all names values.

In your case

Arr::pluck($array, 'name')

Will output

['Test 2322']

Related