Re: Array query - finding the key for a value

From: Date: Fri, 16 Aug 2002 14:42:12 +0000
Subject: Re: Array query - finding the key for a value
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-112960@lists.php.net to get a copy of this message
can do this: $array = array('apple', 'pear', 'orange', 'apricot'); $array = array_flip($array); $keyword = 'orange'; echo "found '$orange' @ index:" . $array[$keyword]; Don't use this method though! It makes your program slow! Elias "Tim Fountain" <tim@tfountain.co.uk> wrote in message news:1599065155.20020816125034@tfountain.co.uk... > > This may be a silly question, but I'm used to being able to find PHP > functions to do whatever I want, but I can't find one to do this! > > If I have an array like this: > > [0] -> 'apple'; > [1] -> 'pear'; > [2] -> 'orange'; > [3] -> 'apricot'; > > I know I can use in_array() to check whether, say, 'orange' is in the > array; but how do I then find out which index 'orange' is at? > > -- > Tim Fountain (tim@tfountain.co.uk) > http://www.tfountain.co.uk/ >

« previous php.general (#112960) next »