Join Up!
104887 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previouselseifwhilenext
Last updated: Sun, 27 Oct 2002
view the printer friendly version or the printer friendly version with notes or change language to Finnish | German | Spanish

Alternativní syntaxe řídicích struktur

PHP nabízí alternativní syntaxi pro některé z řídicích struktur, jmenovitě if, while, for, foreach, a switch. V každém z těchto případů je základním formátem alternativní syntaxe záměna otvírací závorky za dvojtečku (:) a uzavírací závorky za endif;, endwhile;, endfor;, endforeach;, resp. endswitch;.

<?php if ($a == 5): ?>
A se rovná 5
<?php endif; ?>

Ve výše uvedeném příkladu je HTML blok vnořen do konstruktu if napsaném alternativní syntaxí. Tento HTML blok by se zobrazil pouze v případě, že je $a rovno 5.

Alternativní syntaxi lze použít i pro else a elseif. Následující příklad ukazuje strukturu if, elseif a else v alternativním formátu:

if ($a == 5):
    print "a se rovná 5";
    print "...";
elseif ($a == 6):
    print "a se rovná 6";
    print "!!!";
else:
    print "a není ani 5, ani 6";
endif;

Další příklady - viz také while, for, a if.

User Contributed Notes
Alternativní syntaxe řídicích struktur
add a note about notes
There are no user contributed notes for this page.
previouselseifwhilenext
Last updated: Sun, 27 Oct 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST