如何访问嵌套数组值

Dex*_*exx 2 php arrays laravel nest

我需要在 Laravel 电子邮件视图模板中使用以下数组

$inputs['test']
Run Code Online (Sandbox Code Playgroud)

当我dd($inputs['test']);

Array:1[
    "order" => array:2[
        0 => 523
        1 => 522
     ]
 ]
Run Code Online (Sandbox Code Playgroud)

我已经在 foreach 循环中尝试过这个,但它不起作用

foreach($inputs['test']->order as $test){
        echo $test;}
Run Code Online (Sandbox Code Playgroud)

我需要什么语法来回显顺序嵌套数组中的每个值?

小智 5

您可以使用方括号 [] 访问数组值,使用箭头 -> 访问对象的属性

foreach($inputs['test']['order'] as $test){
        echo $test;
}
Run Code Online (Sandbox Code Playgroud)