Created
May 21, 2009 22:39
-
-
Save anselmobattisti/115792 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<? | |
/* | |
* selectArray | |
* @auth Anselmo Battisti | |
* @mail [email protected] | |
* | |
* @version 1.0 | |
* | |
* @example | |
require_once "selectArray.php"; | |
$fruit[0] = 'Lemon'; | |
$fruit[1] = 'Banana'; | |
$fruit[2] = 'Orange'; | |
echo selectArray::getHtmlSelect($fuit,'fruit',$_POST['fuit']); | |
*/ | |
class selectArray | |
{ | |
/** | |
* getHtmlSelect | |
* | |
* @abstract Gera um SELECT html em função de um vetor, a chave do vetor é o value e o option | |
*/ | |
static function getHtmlSelect($array, $name, $selected, $null = false) | |
{ | |
if(!is_array($array)){ | |
$html = "Erro ao gerar o select"; | |
} else { | |
$html = '<select name="'.$name.'" id="'.$name.'" size="1">'; | |
if($null) { | |
$html .= "<option value=''>-----</value>"; | |
} | |
foreach($array as $k=>$v){ | |
unset($s); | |
if($k == $selected) $s = "selected = 'true'"; | |
$html .= '<option value="'.$k.'" '.$s.'>'.$v.'</option>'; | |
} | |
$html .= '</select>'; | |
} | |
return $html; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment