IF / ELSE PHP速记 [英] IF/ELSE PHP shorthand

查看:56
本文介绍了IF / ELSE PHP速记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去的两个小时,我一直在努力编写简写以下PHP条件语句:

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手册:三元运算符

这篇关于IF / ELSE PHP速记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆