Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

[PHP] using integers as array keys From: Alex Rice (alex <email protected>)
Date: 07/07/00

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 <email protected>
// Programmer, Panorama Point web development
// New Mexico, USA
// 505-424-4800x35

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>