note 99708 deleted from function.timezone-identifiers-list by danbrown
| From: | danbrown@php.net | Date: | Tue, 31 Aug 2010 22:49:19 +0000 |
| Subject: | note 99708 deleted from function.timezone-identifiers-list by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172220@lists.php.net to get a copy of this message | ||
Note Submitter: bryan at ravensight dot org
----
Here's an even cleaner example of the multi-dimensional array function. I figured I based it
off of one I saw here, so I might as well reciprocate. Oh yeah, this is meant to reside inside of a
Date/Time utility class. If you want to use it as a global function just remove the "public
static" keywords.
/**
* Builds a multi-dimensional array of time-zones. The first dimension
* represents the "continent" and the second dimension contains all of the
* time-zones that are defined within it.
*
* @return array() or FALSE
*/
public static function buildTimeZones()
{
if (($zones = timezone_identifiers_list()) === FALSE)
{
return FALSE;
}
// end if // (($zones = timezone_identifiers_list()) === FALSE) //
$time_zones = array();
foreach ($zones as $zone)
{
if (strpos($zone, '/') !== FALSE)
{
list($continent, $city) = explode('/', $zone);
}
else
{
$continent = 'Other';
$city = $zone;
}
// end else // if (strpos($zone, '/') !== FALSE) //
if (!array_key_exists($continent, $time_zones))
{
$time_zones[$continent] = array();
}
// end if // (!array_key_exists($continent, $time_zones)) //
$time_zones[$continent][$zone] = $city;
}
// end foreach // ($zones as $zone) //
return $time_zones;
}