Using arrays for look-ups

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jaz

    Using arrays for look-ups

    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.



  • Daniel

    #2
    Re: Using arrays for look-ups


    "Jaz" <xx@xx.com> wrote in message news:bgmksj$ksq $2@news6.svr.po l.co.uk...[color=blue]
    > 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[/color]
    right?[color=blue]
    > As I type this, it seems far more obvious, but if someone could just
    > confirm :-) Thanks!
    >
    > J.
    >[/color]


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

    /D


    Comment

    Working...