Monday, April 10, 2017

ternary operator processing error laravel

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.



via Igor Kolesnikov

Advertisement