Skip to content

Instantly share code, notes, and snippets.

@catoidrobo
Last active April 13, 2016 05:22
Show Gist options
  • Select an option

  • Save catoidrobo/b048bd3dea763ad30fa51e9d4fa1f6bb to your computer and use it in GitHub Desktop.

Select an option

Save catoidrobo/b048bd3dea763ad30fa51e9d4fa1f6bb to your computer and use it in GitHub Desktop.
チェックボックスをチェック済みにするやつの修正版
<?php
$view_arr = array("red", "green", "bule", "Yellow", "black", "white");
$get_arr = array("bule", "Yellow", "black");
// 「in_array()を使えばもうひとつforeachを使わないくても済むのではと」というコメントを頂いたので修正
foreach($view_arr as $val){
if(in_array($val, $get_arr)){
echo '<input type="checkbox" name="hoge[]" value="'.$val.'" checked>'.$val;
}else{
echo '<input type="checkbox" name="hoge[]" value="'.$val.'">'.$val;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment