Home > Mobile >  Declaring a variable in blade php (LARAVEL UPDATED)
Declaring a variable in blade php (LARAVEL UPDATED)

Time:09-09

I have a simple project where Im using laravel with blade. I recive an array called 'tablero' and I have to see all it values. I have this code:

enter image description here

But I received this error: Undefined constant "i" (View: /var/www/html/resources/views/tablero2.blade.php) How do i define i?

CodePudding user response:

add this before foreach

@php 
 $i = 0;
 @endphp

CodePudding user response:

Loops

In addition to conditional statements, Blade provides simple directives for working with PHP's loop structures. Again, each of these directives functions identically to their PHP counterparts:

Solution one:

@for ($i = 0; $i < count($tablero); $i  )
    <p> {{ $tablero[$i] }} </p>
@endfor

Solution two:

@foreach ($tablero as $tab)
    <p> {{ $tab }} </p>
@endforeach
  • Related