Bird
0
0

Given a Laravel controller passes $user = ['name' => 'Anna'] to a Blade template, what will this Blade code output?

medium📝 Predict Output Q4 of 15
Laravel - Views and Blade Templates
Given a Laravel controller passes $user = ['name' => 'Anna'] to a Blade template, what will this Blade code output?
<h1>Hello, {{ $user['name'] }}!</h1>
A<h1>Hello, Anna!</h1>
B<h1>Hello, $user['name']!</h1>
C<h1>Hello, !</h1>
DError: Undefined variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand Blade variable output

    Blade outputs the value inside {{ }} by evaluating PHP expressions.
  2. Step 2: Evaluate the expression $user['name']

    The array key 'name' holds 'Anna', so it outputs 'Anna'.
  3. Final Answer:

    <h1>Hello, Anna!</h1> -> Option A
  4. Quick Check:

    Blade outputs variable value =

    Hello, Anna!

    [OK]
Quick Trick: Use {{ }} to show variable values in Blade [OK]
Common Mistakes:
  • Expecting raw variable name output
  • Forgetting array key syntax
  • Assuming error if variable is array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes