note 106338 modified in control-structures.foreach by danbrown

From: Date: Fri, 28 Oct 2011 23:33:46 +0000
Subject: note 106338 modified in control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184208@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 <?php $passarray = array( "one" => 1, "two" => 2, "three" => 3, "seventeen" => 17 ); ?> function to create the options to select from <?php function create_htmloption($a) { $formatedarray=''; foreach ($a as $k => $v) { $formatedarray.= "<option value=\"$a[$k]\">$v</option> "; } return $formatedarray; } ?> Select creator <?php 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 --was-- 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 http://php.net/manual/en/control-structures.foreach.php

« previous php.notes (#184208) next »