function (). function () fonksiyonu VS () function ()

2 Cevap

I was writing a foreach Loop in PHP5. Here is the script:

foreach(range('A','Z') as $char) // line 1
{ // line 2
echo strtoupper($char)strtolower($char); // line 3
} // line 4

And I got this error message Parse error: parse error, unexpected T_STRING in testing.php on line 3

Ben bu gibi iki işlevler arasında bir nokta eklemek gerekir anlamaya neredeyse bir saat geçirdim:

echo strtoupper($char).strtolower($char);

Yani kodlar bu iki çizgi arasındaki farkı söyleyemem:

echo strtoupper($char).strtolower($char);
echo strtoupper($char)strtolower($char);

2 Cevap

'.' bir birleştirme operatörüdür. Onun sağ ve sol argümanlar birleştirme döndürür.

Örneğin:

'Hello ' . 'world!'

verir:

'Hello world!'

Herhangi operatörleri olmadan birbirlerinin yanında iki işlevleri olan bir hatadır.

PHP 'nin gramer argümanlar echo bir expression veya expressions virgülle ayrılmış bir dizi olmasını bekler.

Şimdi strtoupper($char) kendisi tam bir ifadesidir. Bu ifadeden sonra PHP a comma, dot ya da bir semi-colon olabilir bir ekspresyon ayırıcı görmek için bekler ama bulduğunda bir {[(4)] } (strtolower) o yakınıyor.

Bu yüzden

strtoupper($char)strtolower($char);

Geçerli bir ifade değil ama bunlar:

strtoupper($char),strtolower($char);
strtoupper($char).strtolower($char);
strtoupper($char);strtolower($char);

Sadece 26 büyük harf yazdırır ve küçük olanları baskı yok gibi ama sizin durumda son bir sunucu amaç değil.