Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2004032

[PHP] Re: array_search does not find the first element From: Jason Barnett (jasbarne <email protected>)
Date: 03/31/04

Merlin wrote:

> Hi there,
>
> I am trying to find values inside an array. This array always starts
> with 0.

Do you mean the keys? Or the values? Unnamed keys _should_ start with 0.

> unfortunatelly array_search start searching with the array element 1.
> So the first element is always overlooked.
>
> How could I "shift" this array to start with 1, or make array-search

Careful with your terminology... I almost thought you meant this...
http://www.php.net/function.array-shift

> start with 0?
> The array comes out of an xml webservice, so I can not rally modify the
> results.
>
> array_search($check_date, $results)
>
> Thanx for any help on that.
>
> Merlin

I don't entirely understand what you're trying to do here. See the
manual, it might help you:
http://www.php.net/manual/en/function.array-search.php

If what you're trying to do is use increase the key by one, you can do:

function my_array_search($needle, $haystack, $strict=false) {
     $key = array_search($needle, $haystack, $strict);
     if (is_integer($key)) $key++;
     return $key;
}
my_array_search($xml_service_array);

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