search
LoginSignup
1
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

NULL合体演算子

今日、便利だなと思ったphpの記法をメモ

NULL合体演算子

基本構文

条件式または$変数 ?? 真の式;

条件式または$変数がnullの場合真の式を返し、条件式または$変数がnullでは無い場合、条件式または$変数を返します。
(例)

$name = null;
$username = $name ?? '名無し';
echo $username; // 名無し

(参考
https://www.sejuku.net/blog/23070
https://www.php.net/manual/ja/migration70.new-features.php

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1
Help us understand the problem. What are the problem?