Re: Array question - Finding the name

From: Date: Fri, 07 Jun 2002 14:53:21 +0000
Subject: Re: Array question - Finding the name
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-101120@lists.php.net to get a copy of this message
On Friday 07 June 2002 22:16, Phil Schwarzmann wrote: > Let's say I have an array... > > $my_array[] = array('bob' => $x, 'jim' => $y, 'mike' => > $z); you probably meant to define it as: $my_array = array('bob' => $x, 'jim' => $y, 'mike' => $z); use print_r($my_array) to see the difference between your definition and mine. > Now I want to find the name of the second element in the array (I want > my result to be 'jim') > How do I do this? I think I might have to use the key() function but I > can't quite get it to wkr. Depends on whether you want to find the name of the 'n-th' element, or the name of the element whose value is '$y'. If the former you can use array_slice(), the latter key(). -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* ATM cell has no roaming feature turned on, notebooks can't connect */

« previous php.general (#101120) next »