Re: array_search does not find the first element

From: Date: Wed, 31 Mar 2004 12:57:32 +0000
Subject: Re: array_search does not find the first element
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-181928@lists.php.net to get a copy of this message
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);

« previous php.general (#181928) next »