8 NİSAN 2010, PERŞEMBE
Kıvırcık PHP dize parantez
PHP bir dize çıkış { }
(ayraç) anlamı nedir?
CEVAP
8 NİSAN 2010, PERŞEMBE
Değişken ifadeler kaçmak için kullanıyorlar. Strings:
(Kıvırcık) karmaşık sözdizimi
Bu, çünkü karmaşık değil sözdizimi karmaşık, ama çünkü. karmaşık kullanımı için izin verir ifadeler.
Aslında, ad herhangi bir değer string eklenebilir bu sözdizimi. Sadece yaz ifadesi olduğu gibi aynı şekilde ** 14 , ve dışarıdan görünür sonra { ve } sarın. { Beri kaçmış olması değil, bu sözdizimi sadece hemen $ olduğunda da geçerli olacak {takip ediyor. {\$ A alın {$. değişmez Bazı bunu yapmak için örnekler net:
<?php // Show all errors error_reporting(E_ALL); $great = 'fantastic'; // Won't work, outputs: This is { fantastic} echo "This is { $great}"; // Works, outputs: This is fantastic echo "This is {$great}"; echo "This is ${great}"; // Works echo "This square is {$square->width}00 centimeters broad."; // Works echo "This works: {$arr[4][3]}"; // This is wrong for the same reason as $foo[bar] is wrong outside a string. // In other words, it will still work, but only because PHP first looks for a // constant named foo; an error of level E_NOTICE (undefined constant) will be // thrown. echo "This is wrong: {$arr[foo][3]}"; // Works. When using multi-dimensional arrays, always use braces around arrays // when inside of strings echo "This works: {$arr['foo'][3]}"; // Works. echo "This works: " . $arr['foo'][3]; echo "This works too: {$obj->values[3]->name}"; echo "This is the value of the var named $name: {${$name}}"; echo "This is the value of the var named by the return value of getName(): {${getName()}}"; echo "This is the value of the var named by the return value of \$object->getName(): {${$object->getName()}}"; ?>
"Kaçış" bunu yapabilirsiniz, çünkü:
$a = 'abcd';
$out = "$a $a"; // "abcd abcd";
ya
$out = "{$a} {$a}"; // same
bu durumda, küme parantezi gereksiz ama:
$out = "$aefgh";
edecek, hata seviyesine bağlı olarak, iş ya da yapmanız gereken bir çok değişken $aefgh
adında hayır, çünkü bir hata üretir:
$out = "${a}efgh"; // or
$out = "{$a}efgh";
Bunu Paylaş:
Sekme == 4 boşluk ve otomatik girinti ...
Nasıl parantez (küme parantezleri) biç...
Düzenli ayraç " arasında dize alma...
Kıvırcık parantez bir-gerekli JavaScri...
Parantez arasında bir dize almak için ...