note 56374 deleted from function.strtr by cmb

From: Date: Sun, 29 Dec 2019 10:01:08 +0000
Subject: note 56374 deleted from function.strtr by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213649@lists.php.net to get a copy of this message
Note Submitter: Ezbakhe Yassin <yassin88 at gmail dot com> ---- 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"

« previous php.notes (#213649) next »