1.单选框控件/**
* @param $arr 数组
* @param string $name 控件name
* @param string $checked 默认选中的值
* @param string $ext 其它信息如 id class style 等
* @return string
*/
function makeHtmlRadio($arr, $name = '', $checked = '', $ext = '')
{
$html = '';
$i = 0;
foreach ($arr as $key => $val) {
$id = $name . '_' . $i;
if ($checked == $val) {
$check = ' checked ';
} else {
$check = '';
}
$html .= "$val\r\n";
++$i;
}
return $html;
}
2.复选框控件/**
* @param $arr 数组
* @param string $name 控件name
* @param array $checked 默认选中的值
* @param string $ext 其它信息如 id class style 等
* @return string
*/
function makeHtmlCheckbox($arr, $name = '', $checked = [], $ext = '')
{
$html = '';
$i = 0;
foreach ($arr as $key => $value) {
$id = $name . '_' . $i;
//默认选中
if (in_array($value, $checked)) {
$check = ' checked ';
} else {
$check = ' ';
}
$html .= "{$value}\r\n";
++$i;
}
return $html;
}
3.下拉选择控件/**
* @param $arr 数组
* @param string $name 控件name
* @param string $selected 默认选中的值
* @param string $ext 其它信息如 id class style 等
* @return string
*/
function makeHtmlSelect($arr, $name = '', $selected = '', $ext = '')
{
$html = "";
foreach ($arr as $key => $value) {
if ($selected == $value) {
$select = ' selected ';
} else {
$select = '';
}
$html .= "{$value}\r\n";
}
$html .= '';
return $html;
}