Revision: 15283
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 30, 2009 01:43 by cshaiku
Initial Code
function createSelectMenu($menuName, $menuArray, $selectedID = '1') { $csmBuffer ="<select name=\"$menuName\" class=\"select-control\">\n"; settype($menuArray, 'array'); $arrayCount = count($menuArray); for ($i = 0; $i < $arrayCount; $i++) { if ($selectedID == $menuArray[$i]->id) $csmBuffer .= '<option class="select-current" value="' . $menuArray[$i]->id . '" SELECTED>' . stripslashes($menuArray[$i]->name) . '</option>' . "\n"; else $csmBuffer .= '<option value="' . $menuArray[$i]->id . '">' . stripslashes($menuArray[$i]->name) . '</option>' . "\n"; } $csmBuffer .= "</select>\n"; return $csmBuffer; } $item1->id = 0; $item1->name = 'Item 1'; $item2->id = 1; $item2->name = 'Item 2'; $item3->id = 2; $item3->name = 'Item 3'; $menuArray[0] = $item1; $menuArray[1] = $item2; $menuArray[2] = $item3; $menu = CreateSelectMenu('menu', $menuArray, 1); // Select second item for example echo $menu;
Initial URL
http://code.cshaiku.com/code_php_create_select_menu.php
Initial Description
Initial Title
Create Select Menu from an Array
Initial Tags
html, array
Initial Language
PHP