gpt4 book ai didi

PHP 5.3.3 难题,它打印什么以及为什么

转载 作者:行者123 更新时间:2023-12-02 05:44:36 27 4
gpt4 key购买 nike

为什么它不打印应该打印的内容?

<?php 
$place = 1;
echo $place === 1 ? 'a' : $place === 2 ? 'b' : 'c';
?>

最佳答案

The manual is your friend .引用:

<?php
// on first glance, the following appears to output 'true'
echo (true?'true':false?'t':'f');

// however, the actual output of the above is 't'
// this is because ternary expressions are evaluated from left to right

// the following is a more obvious version of the same code as above
echo ((true ? 'true' : false) ? 't' : 'f');

// here, you can see that the first expression is evaluated to 'true', which
// in turn evaluates to (bool)true, thus returning the true branch of the
// second ternary expression.

你基本上是在做:

echo ($place === 1 ? 'a' : $place === 2) ? 'b' : 'c';
// which is
echo 'a' ? 'b' : 'c';
// which is
echo 'b';

关于PHP 5.3.3 难题,它打印什么以及为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7766425/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com