开发者

PHP syntax question

开发者 https://www.devze.com 2022-12-10 05:16 出处:网络
I fo开发者_如何学Cund this line of code and I\'m trying to comprehend what it\'s doing. The part I\'m not familiar with is the question mark and the colon. What are these characters used for?

I fo开发者_如何学Cund this line of code and I'm trying to comprehend what it's doing. The part I'm not familiar with is the question mark and the colon. What are these characters used for?

$string = $array[1] . ($array[0] === 47 ? '' : ' word');


That's a ternary operator; basically a short-hand conditional.

It's the same as:

$string = $array[1];

if ($array[0] !== 47)
    $string .= ' word';

See this section in the PHP manual (the "Ternary Operator" section).


That's the ternary operator.

Here's a reference to a tutorial

It works somehow like this:

function tern()

    if ($array[0] === 47)
    {
        return '';
    }
    else
    {
        return 'word';
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消