An interview question, no reason found, please answer
蜉蝣
蜉蝣 2020-09-16 21:17:37
0
2
973

if (true) { echo 'true'."\n";} else false : { echo 'false'."\n";}

outputs true fasle

蜉蝣
蜉蝣

reply all(2)
LuLu

false : { echo 'false'."\n";} Replace with label : { echo 'false'."\n";} or abc : { echo 'false'."\n";} or something They all have the same result

The identifier colon code block is part of the goto statement. If goto is not used, you can just treat it as if it is executed sequentially

Can you understand this?

PocketKnife

if (true) {

echo 'true'."\n";

} else false : { //There is a typo here, it should be a semicolon, Why is it a colon?

echo 'false'."\n";

}

if..else... The judgment statement is true, so the first sentence will be output true, else will not be executed

The last false is a separate statement block, which will definitely be output, so the final result is

true

false

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template