note 106338 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:19:40 +0000 |
| Subject: | note 106338 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191942@lists.php.net to get a copy of this message | ||
Note Submitter: bcory at univelocity dot com
----
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