I have problem with my code. I'm sending from controller to blade array with variables. After when I put array into foreach loop and try put variable from this array into another array (i'm doing this in @php directives) $val['id_proces'] is undefined.
@foreach($risk as $ri)
@foreach($tabela as $tab => $val)
@if($ri->id_risk === $val['id_risk'])
@php
array_push($tab1, $val['id_proces']); // not see $val
@endphp
@else
@php
$tab1 = array();
@endphp
@endif
@endforeach
I tried do this like this
{{array_push($tab1, $val['id_proces'])}}
But it's printing everything.
Solution is like this:
@php $tab1 = []; @endphp
@foreach($risk as $ri)
@foreach($tabela as $tab => $val)
@if($ri->id_risk === $val['id_risk'])
@php array_push($tab1, $val['id_proces']); // not see $val @endphp
@else
@php $tab1 = array(); @endphp
@endif
@endforeach
@endforeach
@foreach($tab1 as $tabVal)
{{ $tabVal }}
@endforeach
You can not print the array using {{ }}. To display array you need to set a loop like this: use
{{ dd($tab1) }}
to debug full array