Re: using integers as array keys
| From: | Carroll Barrett | Date: | Fri, 07 Jul 2000 21:15:34 +0000 |
| Subject: | Re: using integers as array keys | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5457@lists.php.net to get a copy of this message | ||
Alex,
I was curious how that would work, so I wrote the following
script (using php4)
function echoIsSet($sub) {
global $myarray;
if(isset($myarray[$sub]))
echo "$sub is set<BR>";
else
echo "$sub is NOT set<BR>";
}
$myarray=array();
$myarray[567]=1;
$myarray[31416]=1;
echoIsSet(0);
echoIsSet(1);
echoIsSet(567);
echoIsSet(1000);
echoIsSet(31416);
echoIsSet(40000);
with the following results.
0 is NOT set
1 is NOT set
567 is set
1000 is NOT set
31416 is set
40000 is NOT set
This isn't what you want?
Regards,
Carroll Barrett
-----Original Message-----
From: Alex Rice <alex@panoramapoint.com>
To: php-general@lists.php.net <php-general@lists.php.net>
Date: Friday, July 07, 2000 4:10 PM
Subject: [PHP] using integers as array keys
>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
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail:
php-list-admin@lists.php.net
>