0

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?

2 Answers2

1

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

Solution three:


@php($i = 0)

@while ($i < count($tablero))
    <p> {{ $tablero[$i] }} </p>
    @php($i++)
@endwhile
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34
0

add this before foreach

@php 
 $i = 0;
 @endphp
Joukhar
  • 724
  • 1
  • 3
  • 18