开发者

Drupal : How to create a String with condition 'if included?

开发者 https://www.devze.com 2023-01-30 18:04 出处:网络
开发者_JAVA百科Is is possible to create a String variable like this : $myString = \'the weather is \' . if ($weather == \'good\') {\'very good\'} else {\'very bad\'};
开发者_JAVA百科

Is is possible to create a String variable like this :

$myString = 'the weather is ' . if ($weather == 'good') {'very good'} else {'very bad'};

It means that if my variable $bad contains the value 'good', $myString is equal to :

'the weather is very good'

I know that I can divide my line in some others instructions but I want to do in only ONE instruction.

Do you understand what I want to do?

Thank you very much,

Bat


This should do the trick for you.

$myString = 'the weather is ' . ($weather == 'good' ? 'very good' : 'very bad');


$myString = 'the weather is ';
$myString .= ($weather == 'good') ? 'very good' : 'very bad';
0

精彩评论

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

关注公众号