IF/ELSE PHP shorthand [duplicate]

别来无恙 提交于 2019-12-13 05:50:59

问题


I'm struggling the past couple of hours to write in shorthand the PHP conditional statement below:

public static $url = $_SERVER['HTTP_REFERER'];

if (false !== strpos($url,'en')) {
    $currlang = 'en';
} else {
    $currlang = 'fr';
}

I can't figure out how to do this although I have tried many variations and I've also read online examples. Can you please help?


回答1:


$currlang = false !== strpos($url, 'en') ? 'en' : 'fr';

PHP Manual: Ternary Operator



来源:https://stackoverflow.com/questions/16026612/if-else-php-shorthand

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!