爲什麼我可以在for循環中使用三元運算符?Php在for循環中使用三元運算符
我使用laravel刀片語法,這就是爲什麼狀態看起來像這樣(@for,@否則,@結束)
<?php
@for($i = 0; $i < isset($Count) ? $Count : 0; $i++)
@else
@end
爲什麼我可以在for循環中使用三元運算符?Php在for循環中使用三元運算符
我使用laravel刀片語法,這就是爲什麼狀態看起來像這樣(@for,@否則,@結束)
<?php
@for($i = 0; $i < isset($Count) ? $Count : 0; $i++)
@else
@end
使用這樣
<?php
@for($i = 0; $i <(isset($Count) ? $Count : 0); $i++)
@else
@end
據the manual?:
是左結合的,這意味着使用的所有東西都用作?
作爲條件,:
和?
右邊的所有東西都用作真實結果,因此$i < isset($Count) ? $Count : 0
表示($i < isset($count)?$count:0
如果這不是你想要的,你需要在()
例如附上你想要的東西。 $i < (isset($Count) ? $Count : 0)
可能是你需要的。
總體上使用括號通常是一個好主意,它們幾乎沒有成本,可以讓你對發生的事情有更多的瞭解。
看看http://stackoverflow.com/questions/25284344/ternary-in-laravel-blade –
有什麼問題?你有什麼錯誤嗎? – hassan