Setting default values (conditional assignment)

后端 未结 5 1916
一生所求
一生所求 2020-12-05 17:26

In Ruby you can easily set a default value for a variable

x ||= \"default\"

The above statement will set the value of x to \"default\" if

5条回答
  •  囚心锁ツ
    2020-12-05 18:12

    As of PHP 5.3 you can use the ternary operator while omitting the middle argument:

    $x = $x ?: 'default';
    

提交回复
热议问题