Yes... for the most part... think about it this way... (and please correct
me if I'm wrong :)

An associative array isn't ordered.  It's key based.  Think of it like a
dictionary, but one whose first and last several pages have been removed.
You wouldn't have any way of telling me the definition for the 100th word
since you don't know.  But you can tell me the definition of "foo" is by
looking it up directly.

And you're not guaranteed anything about their order since, well, they
don't have any order :)  I know that in PHP you can do:

$ary["y"] = "two";
$ary["x"] = "one";
print_r($ary);

and you'll get back:

Array
(
    [y] => two
    [x] => one
)

but you're not *guaranteed* to get it back in the same order you supplied
it.  It just happens that you do in PHP.  Back when I used Perl you
wouldn't necessarily get the same order repeatedly.

hope this helps.

On Wed, 30 Oct 2002, PHP List wrote:

> So are you saying there really is no array pointer?
> Lets say I have an array with several different values like:
> $myarray["a"] = "s";
> $myarray[3] = "d";
> $myarray["sdf"] = "y";
> There is no way of saying give me the value in the array at position 2?
> Since the size of the array is returned as 3, should there not be a way of
> doing this?
>
> Like I said, I seem to be blanking on arrays.
>
> > Because you haven't put anything in array index 0.  The only array index
> > that has anything is "test".  There is no difference between numeric and
> > string indices.  You seem to be assuming that somehow the first element in
> > an array can always be accessed as index 0 which is not the case and never
> > has been.
> >
> > -Rasmus
> >
> > On Wed, 30 Oct 2002, PHP List wrote:
> >
> > > For some reason my brain is not operating within normal parameters this
> week.
> > >
> > > $myarray["test"] = "sd";
> > > echo $myarray[0];
> > >
> > > Why will nothing echo? Do I somehow have to initialize indexing on the
> array $myarray?
> > > php says that $myarray is an array, but I can't access it with numeric
> indexes.
> > >
> > > I know if I do this:
> > > $myarray = array("test"=>"sd");
> > > that I can now echo $myarray[0] and get the value of sd returned.
> > >
> > >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to