note 77670 added to control-structures.switch

From: Date: Fri, 07 Sep 2007 16:11:32 +0000
Subject: note 77670 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-130296@lists.php.net to get a copy of this message
Just a reminder: there may be easier ways to manipulate _long_ lists of data instead of using switches. function getChineseZodiac($year){ // Chinese Zodiac Animals $animals = Array ( 'Monkey', // Years 0, 12, 1200, 2004... 'Rooster', 'Dog', 'Boar', 'Rat', 'Ox', 'Tiger', 'Rabit', 'Dragon', 'Snake', 'Horse', 'Lamb' ); // Number of animals and years in a calendar rotation $numAnimals = count($animals); // Years left until full rotation of calender $yearOffset= round($year) % $numAnimals; return $animals[$yearOffset]; } Of course this is a really generic function, we're just finding how many years away from a full 12 year rotation the current year is. ---- Server IP: 64.71.164.2 Probable Submitter: 65.23.9.242 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/77670 Del: integrated -- https://master.php.net/note/delete/77670/integrated Del: useless -- https://master.php.net/note/delete/77670/useless Del: bad code -- https://master.php.net/note/delete/77670/bad+code Del: spam -- https://master.php.net/note/delete/77670/spam Del: non-english -- https://master.php.net/note/delete/77670/non-english Del: in docs -- https://master.php.net/note/delete/77670/in+docs Del: other reasons-- https://master.php.net/note/delete/77670 Reject -- https://master.php.net/note/reject/77670 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130296) next »