示例代碼:
$array = ['key1' => 'value1', 'key2' => 'value2'];
$value = is_null($array['key3']) ? 'default value' : $array['key3'];
echo $value; // 輸出:default value
示例代碼:
$array = ['key1' => '', 'key2' => 'value2'];
$value = is_null($array['key1']) ? 'default value' : $array['key1'];
echo $value; // 輸出:default value
示例代碼:
$array = ['key1' => 'value1', 'key2' => 'value2'];
$value = isset($array['key3']) ? $array['key3'] : 'default value';
echo $value; // 輸出:default value