note 83490 added to language.variables.scope
| From: | lgrk at osu1 dot php dot net | Date: | Wed, 28 May 2008 13:41:23 +0000 |
| Subject: | note 83490 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139941@lists.php.net to get a copy of this message | ||
Useful function:
<?php
function cycle($a, $b, $i=0) {
static $switches = array();
if (isset($switches[$i])) $switches[$i] = !$switches[$i]; else !$switches[$i] = true;
return ($switches[$i])?$a:$b;
}
?>
Exeample
<?php
for ($i = 1; $i<3; $i++) {
echo $i.cycle('a', 'b').PHP_EOL;
for ($j = 1; $j<5; $j++) {
echo ' '.$j.cycle('a', 'b', 1).PHP_EOL;
for ($k = 1; $k<3; $k++) {
echo ' '.$k.cycle('c', 'd', 2).PHP_EOL;
}
}
}
/**
Output:
1a
1a
1c
2d
2b
1c
2d
3a
1c
2d
4b
1c
2d
2b
1a
1c
2d
2b
1c
2d
3a
1c
2d
4b
1c
2d
*/
?>
----
Server IP: 82.160.94.10
Probable Submitter: 213.25.147.67
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/83490
Del: integrated -- https://master.php.net/note/delete/83490/integrated
Del: useless -- https://master.php.net/note/delete/83490/useless
Del: bad code -- https://master.php.net/note/delete/83490/bad+code
Del: spam -- https://master.php.net/note/delete/83490/spam
Del: non-english -- https://master.php.net/note/delete/83490/non-english
Del: in docs -- https://master.php.net/note/delete/83490/in+docs
Del: other reasons-- https://master.php.net/note/delete/83490
Reject -- https://master.php.net/note/reject/83490
Search -- https://master.php.net/manage/user-notes.php