|
Posted by Daz on 10/22/06 10:52
Andy Hassall wrote:
> On 21 Oct 2006 11:40:15 -0700, "Daz" <cutenfuzzy@gmail.com> wrote:
>
> >Hi Everyone. I know this is a stupid question, but I have been sifting
> >through php.net and I am about ready to pull my hair out over it...
> >
> >I have seen a function similar to in_array() and array_search() which
> >returns the 0-based index number of the specified element if it exists.
>
> Isn't that what array_search already does on numerically-indexed arrays?
>
> Or do you want the index of the key for the element, in the array of keys for
> the array? In which case it sounds like two array_search() calls:
>
> <?php
> $a = array(
> 'fish' => 'fingers',
> 'dog' => 'hot dog',
> 'cow' => 'steak',
> );
>
> print array_search(array_search('hot dog', $a), array_keys($a));
> ?>
>
> Output: 1
>
Hi Andy. Now that achieves exactly what I am looking for without
iterating through the whole array as such.
Many thanks.
Daz
Navigation:
[Reply to this message]
|