Re: how do i get assosciative name in foreach

From: Date: Fri, 08 Aug 2003 18:08:10 +0000
Subject: Re: how do i get assosciative name in foreach
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-158906@lists.php.net to get a copy of this message
From: "Dan Anderson" <dan@mathjunkies.com> > I want to do: > > <?php > > $array['element1'] = 'element1'; > $array['element2'] = 'element2'; > > foreach ($array as $element) > { > // assuming get_assoc gets the assosciative name > if (get_assoc($element) == 'element1') > {get_assoc($element) do_something(); } > elseif ( == 'element1') > { do_somethingelse(); } > } > > ?> Refer to the manual: foreach($array as $key => $value) So... foreach($array as $key => $element) { if($key == 'element1' ... if($key == 'element2' ... ---John Holmes...

« previous php.general (#158906) next »