[nycphp-talk] Accessing First Element of Array
jonbaer at jonbaer.com
Sun Aug 26 21:52:50 EDT 2007
Hmmm I dunno, if that was more towards "what was the way to access
the first element of a hash?" I would say ok, but Im still convinced
most would see an "array" as an object numerically indexed.
But current() it is :-) Time to rewrite all those PHP books ...
On a side note to why the example does not work as expected - (I
think it came up on the list way back):
The docs do not specify this, but adding to the array using the
$my_array = $new_value;
will not advance the internal pointer of the array. therefore, you
cannot use current() to get the last value added or key() to get the
key of the most recently added element.
On Aug 26, 2007, at 9:08 PM, Michael B Allen wrote:
> On 8/26/07, Jon Baer <jonbaer at jonbaer.com> wrote:
>> Is it anything that $array would not be able to get access to?
> Hi Jon,
> Nope. The 0 element is not necessarily first. Consider the
> following example:
> $array = array();
> $array['first'] = 'foo';
> $array = 'bar';
> $ ./t.php
> [first] => foo
>  => bar
> In this case the element 'foo' is first.
> New York PHP Community Talk Mailing List
> NYPHPCon 2006 Presentations Online
> Show Your Participation in New York PHP
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the talk