一、define定义常量问题
define('DATABASE', 'MYSQL');
define('DATABASE_USER', 'ROOT');
define('DATABASE_PASSWORD', 'PASSWORD');
?>
直接使用"DATABASE"常量,代表的就是"MYSQL"。
$arr = array('fruit'=>'apple','veggie'=>'carrot');
define('fruit','veggie');
print $arr['fruit']; // apple
print $arr[fruit]; // carrot
* 注意 :[] 中没有引号。php会自动把key值当作常量来解析,然后去内存中找对应的常量,于是找到了fruit,然后解析key值。然后再去内存中找常量,没找到veggie,然后就把veggie当作真正的key值,找到对应的值。
二、单双引号问题
error_reporting(E_ALL);
$arr = array('fruit'=>'apple','veggie'=>'carrot');
define('fruit','veggie');
print $arr['fruit']; echo '
'; //apple
print $arr[fruit]; echo '
'; //carrot
print "hello $arr[fruit]"; echo '
'; // apple
print "hello {$arr[fruit]}"; echo '
'; // hello carrot
print "hello {$arr['fruit']}"; echo '
';// hello apple
//print "Hello $arr['fruit']"; // 有错误
//print "hello $_GET['foo']"; // 有错误
print "Hello " . $arr['fruit']; // Hello apple
注意: 数组方括号中如果没有加引号,php会首先按照常量来解析。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

禪工作室 13.0.1
強大的PHP整合開發環境

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)