Вопрос

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?

Это было полезно?

Решение

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

PHP Manual: Ternary Operator

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top