using integers as array keys
| From: | Alex Rice | Date: | Fri, 07 Jul 2000 20:49:31 +0000 |
| Subject: | using integers as array keys | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5452@lists.php.net to get a copy of this message | ||
In PHP, I always find myself trying to create hashes with integer keys,
only to rediscover that using an integer index in a PHP associative
array is essentially meaningless. Common example: a query returns a list
of integers which are keys into the database table. I want to simply
stuff those integers into a hash and not worry about the fact that PHP
uses this combination hash/array concept.
$myarray = array();
$myarray[567] = 1;
$myarray[31416] = 1;
// $myarray[0] already isset() !
// $myarray[1] already isset()!
// ... time passes
// is $myarray[27] set?
// who knows?
I could so something wasteful and do $array['my_id_'. $id] = 1, but that
would be silly. Is there a way to get associative arrays more like Perl?
Is there any alternative?
Thanks,
--
// Alex@PanoramaPoint.com
// Programmer, Panorama Point web development
// New Mexico, USA
// 505-424-4800x35