Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93ecc42
commit 7ca07ec
Showing
2 changed files
with
33 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
|
||
|
||
/** | ||
* Output the <options> of a select statement and optionally preselect one | ||
* | ||
* @author Dotan Cohen | ||
* @version 2013-06-30 | ||
* | ||
* @param array $data Associative array to be converted to <options> | ||
* @param string $quote_char Character to use to quote values. Must be " or ' | ||
* @param string $selected Default value to select | ||
* | ||
* @return TRUE | ||
*/ | ||
function output_select_options($data, $quote_char='"', $selected=NULL) | ||
{ | ||
if ( !is_array($data) || !in_array($quote_char, array('"', "'")) ) { | ||
return NULL; | ||
} | ||
|
||
foreach ( $data as $f=>$v) { | ||
$s = $f==$selected ? " selected={$quote_char}selected{$quote_char}" : ''; | ||
echo "<option value={$quote_char}{$f}{$quote_char}{$s}>{$v}</option>"; | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters