note 18271 added to language.variables.variable

From: Date: Wed, 16 Jan 2002 18:40:21 +0000
Subject: note 18271 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-24946@lists.php.net to get a copy of this message
I found a nice use for variable variable names. It was a nice way arround using a whole bunch of if(){} or case statements. I use it to keep track of timezones. Here is a short example from a long list of timezones function get_offset($zone){ ############## # Time Zones # ############## /*---------------North America & Hawaii------------------*/ $ast = -4; //Atlantic Standard Time | GMT - 4 $adt = -3; //Atalantic Daylight Time | GMT - 3 $est = -5; //Easten Standard Time | GMT - 5 $edt = -4; //Eastern Daylight Time | GMT - 4 $cst = -6; //Central Standar Time | GMT - 6 $cdt = -5; //Central Daylight Time | GMT - 5 $mst = -7; //Moutain Standard Time | GMT - 7 $mdt = -6; //Moutain Daylight Time | GMT - 6 $pst = -8; //Pacific Standard Time | GMT - 8 $pdt = -7; //Pacific Daylight Time | GMT - 7 $hst = -10; //Hawaii Standard Time | GMT - 10 $akst = -9; //Alaska Standard Time | GMT - 9 $akdt = -8; //Alaska Daylight Time | GMT - 8 return $$zone; }//END GET_OFFSET The real thing has all the timezones in the world, so it would be too long to show here. Of course this is part of a function within an object so I do some data-type checking to make sure I am getting what I want from the application, but this saved me alot of time, and it works verry quickly, Hope this was helpful! -- http://www.php.net/manual/en/language.variables.variable.php http://master.php.net/manage/user-notes.php?action=edit+18271 http://master.php.net/manage/user-notes.php?action=delete+18271 http://master.php.net/manage/user-notes.php?action=reject+18271

« previous php.notes (#24946) next »