note 92763 modified in control-structures.goto by danbrown

From: Date: Fri, 07 Aug 2009 22:06:08 +0000
Subject: note 92763 modified in control-structures.goto by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159202@lists.php.net to get a copy of this message
Remember if you are not a fan of wild labels hanging around you are free to use braces in this construct creating a slightly cleaner look. Labels also are always executed and do not need to be called to have their associated code block ran. A purposeless example is below. <?php $headers = Array('subject', 'bcc', 'to', 'cc', 'date', 'sender'); $position = 0; hIterator: { $c = 0; echo $headers[$position] . PHP_EOL; cIterator: { echo ' ' . $headers[$position][$c] . PHP_EOL; if(!isset($headers[$position][++$c])) { goto cIteratorExit; } goto cIterator; } cIteratorExit: { if(isset($headers[++$position])) { goto hIterator; } } } ?> --was-- Remember if you are not a fan of wild labels hanging around you are free to use braces in this construct creating a slightly cleaner look. Labels also are always executed and do not need to be called to have their associated code block ran. A purposeless example is below. <?php $headers = Array('subject', 'bcc', 'to', 'cc', 'date', 'sender'); $position = 0; hIterator: { $c = 0; echo $headers[$position] . PHP_EOL; cIterator: { echo ' ' . $headers[$position][$c] . PHP_EOL; if(!isset($headers[$position][++$c])) { goto cIteratorExit; } goto cIterator; } cIteratorExit: { if(isset($headers[++$position])) { goto hIterator; } } } http://php.net/manual/en/control-structures.goto.php

« previous php.notes (#159202) next »