Bird
0
0

Given the Blade code:

medium📝 component behavior Q5 of 15
Laravel - Views and Blade Templates
Given the Blade code:
@foreach(['apple', 'banana'] as $fruit)
  {{ $fruit }}
@endforeach

What will be the rendered output?
Aapple banana
B['apple', 'banana']
Cfruit fruit
DNo output due to syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the @foreach loop

    The loop iterates over the array with two strings: 'apple' and 'banana'.
  2. Step 2: Output each item

    Each iteration outputs the current fruit string, so the output is 'apple banana'.
  3. Final Answer:

    apple banana -> Option A
  4. Quick Check:

    @foreach outputs each array element [OK]
Quick Trick: Each @foreach iteration outputs one array element [OK]
Common Mistakes:
  • Printing the whole array as string
  • Using variable name instead of value
  • Syntax errors in loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes