note 106338 added to control-structures.foreach

From: Date: Fri, 28 Oct 2011 20:44:32 +0000
Subject: note 106338 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-184203@lists.php.net to get a copy of this message
Though i would add this for everyone. I am building a form creation library for myself but this is nice if you need to get list option for a select in a form and pass them through to you gui. If anyone notices any issue will you let me know my example array below $passarray = array( "one" => 1, "two" => 2, "three" => 3, "seventeen" => 17 ); function to create the options to select from function create_htmloption($a) { $formatedarray=''; foreach ($a as $k => $v) { $formatedarray.= "<option value=\"$a[$k]\">$v</option> "; } return $formatedarray; } Select creator function select_field($name, $id, $passarray) { $optionarray=create_htmloption($passarray); $fieldinfo=" <select name=\"$name\" id=\"$id\"> $optionarray </select> "; return $fieldinfo; } $bob=select_field('bob', '2', $passarray); echo $bob; seems fairly simple and might help someone work their select options into a database ---- Server IP: 69.147.83.197 Probable Submitter: 174.79.242.30 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/106338 Del: integrated -- https://master.php.net/note/delete/106338/integrated Del: useless -- https://master.php.net/note/delete/106338/useless Del: bad code -- https://master.php.net/note/delete/106338/bad+code Del: spam -- https://master.php.net/note/delete/106338/spam Del: non-english -- https://master.php.net/note/delete/106338/non-english Del: in docs -- https://master.php.net/note/delete/106338/in+docs Del: other reasons-- https://master.php.net/note/delete/106338 Reject -- https://master.php.net/note/reject/106338 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184203) next »