Re: help with an array if its possible!

From: Date: Wed, 22 Jun 2011 23:44:43 +0000
Subject: Re: help with an array if its possible!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-313668@lists.php.net to get a copy of this message
On Wed, Jun 22, 2011 at 18:43, Adam Preece <ad84@blueyonder.co.uk> wrote: > Hi Gang! > > i have 2 assoc arrays from 2 querys, > > first one is page categorys it consists of: >        id >        name > > second is pages >        name >        cat_id > > now, i am using smarty, so i pass arrays into the view. this i would like to pass to the view > and display within a html select element. > >        <select id="name"> >                <option value="CAT_ID">CAT NAME >                        <option disabled="disabled">PAGE NAME > ASSOCIATED TO THE CAT NAME</option> >                </option> >        </select> > > and i cannot think of how i can structure an array to pass in to achieve this and/or is it even > possible :-/. > > i hope this makes sense. > > i'm truly stuck! If I'm understanding you correctly, this should get you started: <?php $arr = array( 'inventory_100' => 'apples', 'inventory_101' => 'oranges', 'inventory_102' => 'pears', 'inventory_103' => 'bananas', ); echo '<select id="inventory_items">'.PHP_EOL; foreach ($arr as $k => $v) { echo ' <option value="'.$k.'">'.$v.'</option>'.PHP_EOL; } echo '</select>'.PHP_EOL; ?> You can copy and paste that code (though I just typed it in here, it should work) and it should illustrate the point. -- </Daniel P. Brown> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/

« previous php.general (#313668) next »