PHP
1$array = array("1", "3", "5"); 2while($row = $resList->fetchRow()){ 3 if (array_search($row[0], (array)$array) !== FALSE) 4 { 5 echo "<input type= 'checkbox' name='[$row[0]]' value='$row[0]' checked >"; 6 } 7 else {echo "<input type= 'checkbox' name='[$row[0]]' value='$row[0]' >";} 8}
丸投げですみません。PHP初心者です。
$row=array("1", "2", "3","4", "5", "6");
です。
$arrayの1、3、5と$row[0]が一致する場合のみ
echo "<input type= 'checkbox' name='[$row[0]]' value='$row[0]' checked >";
を出力したいです。
ほしい結果↓
<input type= 'checkbox' name='1' value='1' checked >
<input type= 'checkbox' name='1' value='2'>
<input type= 'checkbox' name='3' value='3' checked >
<input type= 'checkbox' name='1' value='4'>
<input type= 'checkbox' name='5' value='5' checked >
<input type= 'checkbox' name='1' value='6'>
上記のコードで問題ないでしょうか?
よろしくお願いいたします。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/19 16:29
2017/06/19 16:52