NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing First Element of Array

Dell Sala dell at sala.ca
Sun Aug 26 21:25:27 EDT 2007


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[0] would not be able to get access to?
>
> Nope. The 0 element is not necessarily first. Consider the  
> following example:
>
> $array = array();
> $array['first'] = 'foo';
> $array[] = 'bar';


How about this:

$values = array_values($array);
$first = $values[0];

-- Dell




More information about the talk mailing list