Re: two dimensional array or two arrays?

From: Date: Tue, 28 Aug 2001 19:37:07 +0000
Subject: Re: two dimensional array or two arrays?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-64871@lists.php.net to get a copy of this message
this should do it for you. $categoryarry = array(array("","none"),array("1","John"),array("2","Jim")); foreach($categoryarray as $value) { if($value[0] == $srch_cat) { $cat_option .= "<option value=\"$value[0]\"selected>$value[1]</option>\n"; } else { $cat_option .= "<option value=\"$value[0]\">$value[1]</option>\n"; } } ----- Original Message ----- From: Tom Beidler <tom@orbittechservices.com> To: php list <php-general@lists.php.net> Sent: Tuesday, August 28, 2001 12:23 Subject: [PHP] two dimensional array or two arrays? > I have some code I use to create pulldown menus. It's as follows; > > $categoryarry = > array("","1","2","3","4","5"); > while (list($key,$value) = each($categoryarry)) { > if ($value == $srch_cat) { > $cat_option .= "<option > value=\"$value\"selected>$value</option>\n"; > } else { > $cat_option .= "<option > value=\"$value\">$value</option>\n"; > } > } > > It works fine when the pulldown value and displayed text are the same, ie. > > <option value="John">John</option> > > But now I would like to change so the value is different then what's > displayed in the menu, ie. > > <option value="1">John</option> > > I've never used two dimensional arrays but I thought it might be what I need > to look into. Or should I have to arrays and use one for the value and the > other for the item displayed in the pulldown menu. > > Any help appreciated. > > Thanks, > Tom > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#64871) next »