Php > Arrays
In a lot of dynamic forms or content management sytems the form element
In a lot of dynamic forms or content management sytems the form element "SELECT" is used frequently. If you use your PHP code inside the standard HTML element the code will be nearly unreadable. Adding extra options is not really fun. This small handy function will produce a select based on an associative array. Just define an array and call the function, that's all. "first label", "some_var"=>"it's hot", "last_constant"=>"last element"); // the properties of this function the array above, the name of the select menu and the initial value. // If the initial value is empty (by default the an empty option is added otherwise. // Use only a valid key from the above array as initial value and the selected state is used for this value. function dynamic_select($the_array, $element_name, $init_value = "") { $menu = "
\n"; if (!isset($_REQUEST[$element_name])) { if ($init_value == "") { $menu .= "
...\n"; } else { $curr_val = $init_value; } } else { $curr_val = $_REQUEST[$element_name]; } foreach ($the_array as $key => $value) { $menu .= "
first label
it's hot
last element
*/ ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage