You are here: Re: Can't find built-in PHP function which I know exists... « PHP Programming Language « IT news, forums, messages
Re: Can't find built-in PHP function which I know exists...

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация