Home > Back-end >  How do I access to my variable in an array of array of array?
How do I access to my variable in an array of array of array?

Time:03-03

I want to access to 'image'

enter image description here

I reached my array 'questions' with this $file = $request->files->get('quiz')['questions']; but I can't go further

Can you help me please

CodePudding user response:

Based on your screen shot you could,

$image = $request->files->get('quiz')['questions'][0]['image'];

Each nested level is an array so you can walk all the way down using the array keys.

Note that [0] will be the first question, but you probably want all the questions. If so, you can loop over them.

foreach ($request->files->get('quiz')['questions'] as $question) {
    $image = $question['image'];
    //
}

CodePudding user response:

The scalaire value on the get is depreciated now.

You can use the "all" :

foreach ($request->files->all('quiz')['questions'] as $question) {
    $image = $question['image'];
}
  • Related