时间:2021-07-01 10:21:17 帮助过:21人阅读
$arr = array(
0 => array('id'=>12,'name'=>'NO.1'),
1 => array('id'=>13,'name'=>'NO.2'),
);
$_check_id = 0;
if($arr) {
foreach($arr as $v){
?>
}
}?>
$arr = array(
0 => array('id'=>12,'name'=>'NO.1'),
1 => array('id'=>13,'name'=>'NO.2'),
2 => array('id'=>14,'name'=>'NO.3'),
3 => array('id'=>15,'name'=>'NO.4'),
);
$_check_id = 14;
$found = false;
$htmls = array();
if($arr) {
foreach($arr as $v){
$input_pre = <<EOT;
$input_post = <</>{$v['name']}
EOT;
if(!$found && $_check_id == $v['id']) {
$found = true;
$input_pre .= ' checked ';
}
$htmls[] = array($input_pre, $input_post);
}
}
$htmlstr = '';
foreach($htmls as $html) {
if(!$found) {
$html[0] .= ' checked ';
$found = true;
}
$htmlstr .= implode('', $html);
}
echo $htmlstr;
$arr = array(
0 => array('id'=>12,'name'=>'NO.1'),
1 => array('id'=>13,'name'=>'NO.2'),
2 => array('id'=>14,'name'=>'NO.3'),
);
$_check_id = 0;
if($arr) {
foreach($arr as &$v) {
if($_check_id == $v['id']) {
$v['check'] = ' checked';
$_check_id = -1;
}
}
if($_check_id >=0) $arr[0]['check'] = ' checked';
foreach($arr as $v){
?>
/>
}
}?>
foreach($arr as $key=>$v){
if($key == $_check_id){
//这儿是checked
continue;
}
......