官术网_书友最值得收藏!

Null coalescing operator

The Null coalescing operator (??) is a syntactical sugar, but a very important one. Previously in PHP5 when we were having some variable which could be undefined, we used the ternary operator as follows:

$username = isset($_GET['username']) ? $_GET['username'] : '';

However, now in PHP7, we can simply write:

$username = $_GET['username'] ?? '';

Although this is just a syntactical sugar, it can save time and make code cleaner.

主站蜘蛛池模板: 镇远县| 贺州市| 华池县| 吉首市| 信丰县| 安乡县| 湖南省| 梅州市| 孝感市| 辉县市| 利川市| 应城市| 屯留县| 台湾省| 唐海县| 喀喇| 谢通门县| 英德市| 邵东县| 武鸣县| 武乡县| 马尔康县| 荆州市| 额敏县| 平度市| 班玛县| 永嘉县| 田东县| 水城县| 泸西县| 呼伦贝尔市| 镇康县| 库伦旗| 黑龙江省| 涿鹿县| 黄山市| 上杭县| 东平县| 开封市| 明光市| 安庆市|