php常量的声明和使用
常量可以理解为值不变的量,常量被定义后,在脚本的其他任何地方都不能改变,一个常量由英文字母,下划线,和数字组成,但是数字不能作为常量的首字母。
在php中使用#define()函数来定义常量,该函数的语法格式如下:
define(string constant_name,mixed value,case_sensitive=true)
获取常量的值的方法有两种,一种方法是:使用常量的名字直接获取值,第二种方法是利用constant()函数,第二种方法是利用constant()函数和直接使用常量名输出的效果一样,但是函数可以动态的输出不同的常量的值,这样的更加灵活方便的多。
第一种直接用常量的名字获取其值
<?php define("test","I am Jack!"); echo test; ?>
运行结果如下:
第二种使用constant()函数获取常量的值代码如下:
<?php define("test","I am Jack!"); $jackStr ="test"; echo constant($jackStr); ?>
运行结果如下:
接下来咱们说一下大小写敏感的问题,刚才常量的声明有设置大小写敏感,我们用代码验证一下看看到时是不是,另外还可以增强我的们的记忆
代码如下:
<?php define("test","I am Jack!",true);echo test;echo "\n";echo Test;echo "\n";echo TEST;echo "\n"; ?>
咱们再看一下输出的结果吧
大家可以发现设置为大小写不敏感的话,即使出现大小写不一样的问题,但是输出的结果仍然是一样的。
预定义常量和我们自己定义的常量一样在使用上没有什么差别,常见的预定义常量如下:

LeicareleasedtheLeicaLuxcameraappfortheAppleiPhoneafewdaysago.However,theappwasnotdevelopedbyLeica,butbyFjorden.ThecompanyhasbeenknownprimarilyforitscameragripsfortheiPhoneandwasacquiredbyLeicainDecember2023.Fo

SincethedemiseofLogitech'spopularHarmonyremotecontrols,themarketforhigh-qualityuniversalremotecontrolshasbeenfragmentedatbest.UnfoldedCircleaimstoavoidthefateoftheHarmonyUltimatebyeliminatinganyserverobligationsorsubs

In2012,theeminentautomotivejournalistJeremyClarksonstatedthattheLamborghiniAventador,whichhewasreviewingatthetime,wouldbeamongthelastcarstofeatureanaturallyaspiratedV12.Morethanadecadelater,V12-poweredsupercarsareal

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

Audio-TechnicahasunveiledtheATH-S300BTwirelessheadphoneswithhear-throughnoise-cancellation,multipointpairing,and90hoursofbatterylife.Thenoise-cancellingfeaturehasthreemodes:off,on,andhear-through,whereambientsoundscanbehea

Backin2022,whenPCIe7.0wasstartingtotakeshapeasafuturestandard,PCIe5.0wasjusthittingtheservermarketsandtheprospectofseeingPCIe6.0devicesavailableanytimesoon,letalonePCIe7.0ones,wasquitefar-fetched.CurrentlyPCIe5

TheJabraEliteserieshascometoanend,withGNCEOPeterKarlstromerannouncingthediscontinuationofthewirelessearbudswithinthelineupinapressrelease.Petersaysthatthechangingmarketdynamicsandhowchallengingithasbecometogetas

TheHYgreenGOMOWrobotlawnmowerisduetolaunchinGermanysoonandcouldarriveinothercountriesinthefuture.Theproductwillbeshownatspoga+gafa2024inColognefromJune16thto18th,withtheCalifornia-basedcompanylocatedatHall5.1St


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

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

Dreamweaver CS6
視覺化網頁開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。