IF/ELSE PHP shorthand [duplicate]
Asked Answered
T

1

0

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?

Tiossem answered 16/4, 2013 at 0:2 Comment(2)
if (strpos($url,'en') !== false)... makes more sense when you read the code.Respectful
@MarkBiek Maybe you missed the last sentence of my question. I needed some help because I couldn't make it work myself.Tiossem
I
6
$currlang = false !== strpos($url, 'en') ? 'en' : 'fr';

PHP Manual: Ternary Operator

Ingrowing answered 16/4, 2013 at 0:3 Comment(1)
Thanks! That was fast. I need more practice to understand the logic.Tiossem

© 2022 - 2024 — McMap. All rights reserved.