Re: Array question - Finding the name

From: Date: Fri, 07 Jun 2002 15:59:23 +0000
Subject: Re: Array question - Finding the name
Groups: php.general 
Request: Send a blank email to php-general+get-101132@lists.php.net to get a copy of this message
Thanks for your reply! I tried using array_slice but I don't think that's exactly that I want to do. I want to find the name of the n-th value in an array. Not the value of the n-th, but whatever name was given to it. Array_slice seems to just pull part of an array and put it in another. and key() isn't exactly what i want either.. >>> php-general@gremlins.com.hk 06/07/02 10:53AM >>> 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 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#101132) next »