Search code examples
phparrayslaravelnest

How to access nested array values


I have the following array that I need to use in a laravel email view template

$inputs['test']

Which looks like this when I dd($inputs['test']);

Array:1[
    "order" => array:2[
        0 => 523
        1 => 522
     ]
 ]

I've tried this in my foreach loop but it doesn't work

foreach($inputs['test']->order as $test){
        echo $test;}

What syntax would I need to echo each value from the order nested array?


Solution

  • You have to use array not object loop:

    foreach($inputs['test']['order'] as $test){           
            echo $test;
    
    }