Bu PHP sözdizimi ne tür?

4 Cevap php
if(true):
    echo 'good';
endif;

Ben bugün sadece PHP görmek ettik!

Ben hep kullanıyorum:

if(true)
{
   echo 'good';
}

4 Cevap

Bu Alternative syntax for control structures olduğunu.


Quoting that page of the manual :

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.


I don't often see it used in "pure PHP" files, but it's quite often used when PHP is mixed with HTML in the same file -- i.e. when used as a templating language.

Sen çok kolay html ile eski geçmeli olabilir.

http://php.net/manual/en/control-structures.alternative-syntax.php

PHP gösterimi:

if(x=1):
  dosomething();
elseif(x=2):
  dosomethingelse();
  andanotherthing();
else:
  doesntmatcheither();
endif;

de ilgilidir

$var=(query?true:false);

hatta daha fazla steno içinde

$var=query?true:false;

Ama ben şahsen parantez atlayarak sevmiyorum; Bana paranoyak diyebilirsiniz ;)

Aynı etki, hayır diference ve benim kişisel görüşüme teklif iyi readble kodu ve temiz sözdizimi, ayrıca sonu gibi kapanış anahtar kelime bir kapanış yerine parantez bir demet tahmin hangi göstermek için, iç içe kontrol yapıları yardımcı olabilir.