note 56374 added to function.strtr
| From: | EzbakheYassin | Date: | Wed, 31 Aug 2005 22:55:09 +0000 |
| Subject: | note 56374 added to function.strtr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94552@lists.php.net to get a copy of this message | ||
Here you are a simple function to rotate a variable according to an array of possible values. You
can make a strict comparison (===).
<?php
function rotateValue($string, $values, $strict = TRUE)
{
if (!empty($string) AND is_array($values))
{
$valuesCount = count($values);
for ($i = 0; $i < $valuesCount; $i++)
{
if ($strict ? ($string === $values[$i]) : ($string == $values[$i]))
{
return $values[($i + 1) % $valuesCount];
}
}
}
return FALSE;
}
?>
For example:
- rotateValue("A", array("A", "B", "C")) will return
"B"
- rotateValue("C", array("A", "B", "C")) will return
"A"
----
Manual Page -- http://www.php.net/manual/en/function.strtr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56374
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56374&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56374&report=yes
Search -- http://master.php.net/manage/user-notes.php