How to access nested array values

后端 未结 6 1801
轮回少年
轮回少年 2021-01-26 18:03

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[

6条回答
  •  生来不讨喜
    2021-01-26 18:07

    Try

    $inputs['test']['order'][0]

    Basically, php reads the nested arrays as arrays in arrays .. so no matter how many arrays nested you can always use [][][][][]

    php manual

    Example #6 Accessing array elements

     "bar",
        42    => 24,
        "multi" => array(
             "dimensional" => array(
                 "array" => "foo"
             )
        )
    );
    
    var_dump($array["foo"]);
    var_dump($array[42]);
    var_dump($array["multi"]["dimensional"]["array"]);
    ?>
    

    and you can use it in looping as such

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

提交回复
热议问题