I have this problem. In plain PHP, this function is working perfectly and returns correct result:
$focos_3[ (array_search("$c", $cidades_3) ? array_search("$c", $cidades_3) : ('') ) ]
OBS: sometimes $c is not set.
But when I put it in Laravel its stops working and throw me "Undefined index:". Without index indication.
Doing some tests, I found that if I do this:
array_search("$c", $cidades_3)
or this
in_array("$c", $cidades_3)
works perfectly, even if $c is not set.
Some answers:
$cidades_3 starts at index 1 $focos_3 is array of values that will return a result on position that was requested.
The whole function which I need to get working is this:
foreach ($cidades as $c)
{
$registros = array(
"Estado" => $estados[$c],
"Municipio" => $c,
"tres_dias" => $focos_3[ (array_search("$c", $cidades_3) >=0 ? array_search("$c", $cidades_3) : ('') ) ],
"dois_dias" => $focos_2[ (array_search("$c", $cidades_2) >=0 ? array_search("$c", $cidades_2) : ('') ) ],
"um_dia" => $focos_1[ (array_search("$c", $cidades_1) >=0 ? array_search("$c", $cidades_1) : ('') ) ],
"total" => (
($focos_3[ (array_search("$c", $cidades_3) >=0 ? array_search("$c", $cidades_3) : ('') ) ]) +
($focos_2[ (array_search("$c", $cidades_2) >=0 ? array_search("$c", $cidades_2) : ('') ) ]) +
($focos_1[ (array_search("$c", $cidades_1) >=0 ? array_search("$c", $cidades_1) : ('') ) ])
)
);
}
And yes, its similar problem to this question (Laravel breaks entire app on PHP notices), but there we have not very goo solution (suppression error).