PHP - If/else, for, foreach, while - without curly braces?

后端 未结 12 1655
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 05:31

Something that really would like to know but never found out are shortcuts in PHP.

I am currently coding a function with a foreach loop with just a sing

12条回答
  •  萌比男神i
    2020-11-27 06:07

    You can use it for simple things like:

    if($a === true) continue;
    

    But for some more complicated sub-conditions it may cause you problems:

        $a = false;
        $b = false;
        if ($a === true)
            if ($b === true)
                echo 1;
        else
            echo 2;
    

    With the code above, you would expect to see "2" as output, but you won't.

提交回复
热议问题