By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Using arrays for look-ups

P: n/a
Jaz
Hi,

Just a quick sanity check...

Sometimes it's useful to use an array as a kind of reverse lookup. For
example, the indexes being productIDs and the value being it's name.

If I do something like this...

$x = array();
$x[1] = 'foo';
$x[345] = 'foo';
$x[12345] = 'foo';

.... PHP is intelligent enough only to allocate 3 data chunks for this right?
As I type this, it seems far more obvious, but if someone could just
confirm :-) Thanks!

J.

Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Jaz" <xx@xx.com> wrote in message news:bg**********@news6.svr.pol.co.uk...
Hi,

Just a quick sanity check...

Sometimes it's useful to use an array as a kind of reverse lookup. For
example, the indexes being productIDs and the value being it's name.

If I do something like this...

$x = array();
$x[1] = 'foo';
$x[345] = 'foo';
$x[12345] = 'foo';

... PHP is intelligent enough only to allocate 3 data chunks for this right? As I type this, it seems far more obvious, but if someone could just
confirm :-) Thanks!

J.

Yeah that's right. sizeof($x) will return 3 and NOT 12346. :-)

/D
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.