PHP code example of flsouto / array2options
1. Go to this page and download the library: Download flsouto/array2options library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flsouto / array2options example snippets
ices = ['apple','orange','banana'];
echo "<select name=\"fruit\">\n";
echo "<option value=\"none\">Choose a Fruit:</option>\n";
echo array2options($choices);
echo "</select>";
ices = ['apple','orange','banana'];
echo "<select name=\"fruit\">\n";
echo "<option value=\"none\">Choose a Fruit:</option>\n";
echo array2options($choices, "orange");
echo "</select>";
ices = [
'none' => 'Choose a Color',
'#C0C0C0' => 'Silver',
'#FF0000' => 'Red',
'#000000' => 'Black'
];
echo "<select name=\"color\">\n";
echo assoc2options($choices);
echo "</select>";
ows fetched from database
$rows = [
[
'id' => 93,
'name' => 'Category 1'
],
[
'id' => 102,
'name' => 'Category 2'
],
[
'id' => 106,
'name' => 'Category 3'
]
];
// Prepends a "caption" option
array_unshift($rows, ['id' => 0, 'name'=>'Choose a Category']);
// Renders
echo "<select name=\"category_id\">\n";
echo dataset2options($rows);
echo "</select>";