admin 發表於 2018-10-24 14:25:19

常數

define('PI',3.14);
echo PI;1. 常數名稱的前面沒有 $ 符號。
2. 通常以大寫字母來定義名稱。
3. 常數不能修改。

admin 發表於 2018-10-24 14:28:20

define('DATA',array('a','b','c'));
在 PHP7 之後,可以將陣列作為常量的值。

redd 發表於 2020-10-17 16:06:35

<?php
define("cars", ["Alfa Romeo","BMW","Toyota"]);
echo cars;
?> 結果: Alfa Romeo


redd 發表於 2020-10-17 16:08:33

<?php
define("GREETING", "Welcome!");

function myTest() {
echo GREETING;
}

myTest();
?> Constants are automatically global and can be used across the entire script.


頁: [1]
查看完整版本: 常數