Warning: Undefined variable $kind in /home4/wgate/public_html/include/checkfunpdo.php on line 662

Warning: Undefined variable $vers in /home4/wgate/public_html/include/checkfunpdo.php on line 662

Warning: Undefined variable $kind in /home4/wgate/public_html/include/checkfunpdo.php on line 662

Warning: Undefined variable $vers in /home4/wgate/public_html/include/checkfunpdo.php on line 662
:::| 目前位置圖示目前位置:首頁圖示回首頁 | 主功能頁圖示相關問答
判斷變數是否存在,使用PHP 7+ Null 合併運算子

[日期]:2026/04/07  [瀏覽人數]:80

echo ($name ?? "查無資料");

當變數不存在時,在舊的PHP5不會產生錯誤,但PHP8會顯示錯誤訊息

如:echo "數量=" . $articlefun[0];

在PHP5不會出現錯誤,在PHP8將會顯示錯誤

可以改成

1.

if (isset($articlefun[0]))

    echo $articlefun[0];

else

    echo "查無資料";

2.

echo ($articlefun[0] ?? "查無資料");