Last active
April 13, 2016 05:22
-
-
Save catoidrobo/b048bd3dea763ad30fa51e9d4fa1f6bb 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
| <?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