引号中,任何变量($var)、特殊转义字符(如“t r n”等)不会被解析,因此php的解析速度更快,转义字符仅仅支持“’”和“”这样对单引号和反斜杠本身的转义;
在字串中使用变量
这个功能让你无须使用连接符号来粘和大量的简单字符串,php允许我们在双引号串中直接包含字符串变量,我们可以发现下面的两个字串的处理结果是相同的。
$full_name = $first_name . ' ' . $last_name;
$full_name = "$first_name $last_name";
单引号串和双引号串在php中的处理是不相同的。双引号串中的内容可以被解释而且替换,而单引号串中的内容总被认为是普通字符。例如:在字符串中引用复杂的变量组合时,可能会产生一些问题,下面的代码会正常工作:
echo "value = $foo";echo "value = $a[$i]";
而下面的代码却不能得到我们希望的结果:
echo "value = $a[$i][$j]"; //我们希望打印二维数组$a的某个元素。
为避免这些字串使用中的潜在问题,我们通常把复杂的变量从字串中分离开来,就像这样:
echo 'value = ' . $a[$i][$j];
还有一种办法是将复杂变量用花括号括起来,语法分析器就能正确辨认了:
echo "value = {$a[$i][$j]}" //打印二维数组$a的某个元素
这样,又出现新问题了。当我们想在字串中引用花括号字符本身时,就要记得使用转义符了:
- $var = 3;
- echo "value = {$var}"; // 打印结果 "value = 3"
- echo "value = {$var}"; // 打印结果 "value = {3}"
- $foo = 2;
- echo "foo is $foo"; // 打印结果: foo is 2
- echo 'foo is $foo'; // 打印结果: foo is $foo
- echo "foo is $foon"; // 打印结果: foo is 2 (同时换行)
- echo 'foo is $foon'; // 打印结果: foo is $foon
双引号中,变量($var)值会代入字符串中,特殊转义字符也会被解析成特定的单个字符,还有一些专门针对上述两项特性的特殊功能性转义,例如“$”和“{$array[‘key’]}。这样虽然程序编写更加方便,但同时php的解析也很慢;
引号内部的变量不会执行,双引号会执行,如:
- $name = 'hello';
- echo "the $name";
会输出 the hello,而如果是单引号:
- $name = 'hello';
- echo 'the $name';
会输出 the $name,主要区别就是这个,其他的无所谓,看你自己喜欢了,推荐是保持一致,如用单引号其他地方保持一致就可以了.
波比源码 » php中单引号与双引号的区别
purchase levaquin purchase levaquin pills
dutasteride pills purchase tamsulosin generic buy zofran 8mg without prescription
spironolactone 100mg pill diflucan 100mg over the counter diflucan over the counter
cheap ampicillin buy cephalexin for sale buy erythromycin 250mg for sale
order fildena 100mg online cheap buy careprost buy generic methocarbamol
sildenafil for sale online buy estrace 2mg generic purchase estradiol online cheap
oral lamotrigine 50mg purchase lamotrigine without prescription tretinoin cream us
order tadalis 10mg online tadalafil 10mg oral diclofenac 100mg cheap
order indocin 75mg pill buy terbinafine 250mg without prescription amoxicillin 500mg without prescription
anastrozole 1mg canada buy biaxin without prescription oral sildenafil 50mg
tadalafil 5mg generika tadalafil generika rezeptfrei kaufen sildenafil 100mg kaufen für männer
accutane 40mg sale zithromax 250mg generic buy ivermectin for humans australia
modafinil 200mg us order diamox 250mg for sale acetazolamide 250mg for sale
buy altace for sale astelin 10 ml over the counter azelastine oral
order alendronate 35mg without prescription famotidine 40mg oral buy famotidine without prescription
prograf over the counter labetalol 100mg drug ursodiol for sale online
order imdur 40mg generic lanoxin 250 mg without prescription telmisartan order online
generic bupropion order zyban 150mg generic quetiapine 50mg us
order tadalafil for sale buy tadalafil pills order amantadine 100 mg pills
buy naltrexone 50mg online generic letrozole aripiprazole 30mg usa
order generic provera microzide canada cyproheptadine over the counter
purchase luvox buy generic fluvoxamine 50mg buy glucotrol 10mg generic
buy accutane 10mg for sale brand amoxil 250mg prednisone 40mg generic
order azithromycin online cheap neurontin 800mg cost order neurontin generic
order cialis 10mg online cialis without a doctor prescription order anafranil online
sporanox 100 mg oral buy prometrium 100mg sale order tinidazole 300mg for sale
glycomet over the counter order glycomet 1000mg cheap tadalafil sale
viagra 100mg brand viagra tablet buy lisinopril online cheap
prilosec 10mg oral buy omeprazole online cheap ocean casino online
zyvox 600mg cheap zyvox 600mg ca roulette online real money
buy generic lopressor 100mg buy lopressor online cheap brand levitra 20mg
college essay for sale play roulette free for fun best online gambling
dapoxetine 60mg oral order generic priligy 60mg order synthroid online
orlistat pills acyclovir 800mg usa zovirax 800mg without prescription
buy tadalafil 40mg without prescription clopidogrel buy online clopidogrel oral
purchase allopurinol pill ezetimibe for sale online zetia price
methotrexate 10mg uk order methotrexate 2.5mg for sale reglan 20mg brand
ozobax without prescription toradol 10mg usa buy toradol
casino online slot machine gambling casino online
purchase cialis online cheap cost tadalafil ciprofloxacin 500mg brand
keflex 500mg cost cheap erythromycin erythromycin without prescription
overnight delivery for viagra order cialis 10mg for sale cheap cialis online
ceftin 500mg sale order ceftin sale robaxin pills
trazodone order online purchase aurogra aurogra 50mg ca
viagra sildenafil 50mg viagra order online tadalafil 10mg price
online poker free male erection pills cheap cialis generic
zithromax 250mg ca cheap prednisolone tablets purchase gabapentin generic
lasix drug order lasix pill order hydroxychloroquine 200mg without prescription
purchase sildenafil online tamoxifen cost budesonide uk
cheap prednisone 5mg prazosin online buy mebendazole 100mg cost