Better multidimensional search

Hello all,
I'm pretty sure there's a better way to do this without having to explore
the whole array until a match is found, but the solution escapes me at the
moment:

foreach ($Array as $key)
if ($key[1]===$Whatever) {
$Found=$key[0];
break;
}

--
Guillaume Dargaud
http://www.gdargaud.net/
Guillaume Dargaud [ Mi, 16 Januar 2008 23:32 ] [ ID #1909769 ]

Re: Better multidimensional search

On 16 Sty, 23:32, "Guillaume Dargaud" <USE_MY_WEB_F... [at] gdargaud.net>
wrote:
> I'm pretty sure there's a better way to do this without having to explore
> the whole array until a match is found, but the solution escapes me at the
> moment:
>
> foreach ($Array as $key)
> if ($key[1]===$Whatever) {
> $Found=$key[0];
> break;
> }

If you're looking for key instead of item you should write:

foreach( $array as $key => $item )...

looking for item? use array_search.
elmosik [ Mi, 16 Januar 2008 23:44 ] [ ID #1909770 ]

Re: Better multidimensional search

> If you're looking for key instead of item you should write:
> foreach( $array as $key => $item )...
Right, I should have written $item

> looking for item? use array_search.
Hmmm... But I'm looking only in the 2nd 'column' of a 2D array. array_search
or in_array don't let me narrow down the search for a specific column. How
can I do that ?

--
Guillaume Dargaud
http://www.gdargaud.net/
Guillaume Dargaud [ Do, 17 Januar 2008 23:42 ] [ ID #1910797 ]
PHP » comp.lang.php » Better multidimensional search

Vorheriges Thema: problems with $_FILES
Nächstes Thema: PHP store solution that allows for multiple unique storefronts per