fork download
  1. <?php
  2.  
  3. //Test
  4. $row = array(
  5. 'maker' => '',
  6. 'type' => 'e,f',
  7. );
  8.  
  9. $maker_flag = $row['maker'];
  10. $type_flags = array_flip(explode(',', $row['type']));
  11.  
  12. $maker_names = array(
  13. '' => 'なし',
  14. 'a' => 'A',
  15. 'b' => 'B',
  16. 'c' => 'C',
  17. );
  18. $type_names = array(
  19. 'd' => 'D',
  20. 'e' => 'E',
  21. 'f' => 'F',
  22. );
  23.  
  24. $maker_format = '<option value="%s"%s>%s</option>'.PHP_EOL;
  25. $type_format = <<< 'EOD'
  26. <label class="checkbox inline">
  27. <input type="checkbox" name="sol[]" value="%s"%s>%s</option>
  28. </label>
  29.  
  30. EOD;
  31.  
  32. echo '<label>メーカー</label>'.PHP_EOL;
  33. echo '<select name="maker">'.PHP_EOL;
  34. foreach ($maker_names as $value => $name) {
  35. printf($maker_format,
  36. $value,
  37. $maker_flag === $value ? ' selected' : '',
  38. $name
  39. );
  40. }
  41. echo '</select>'.PHP_EOL;
  42.  
  43. echo '<label>タイプ</label>'.PHP_EOL;
  44. foreach ($type_names as $value => $name) {
  45. printf($type_format,
  46. $value,
  47. isset($type_flags[$value]) ? ' checked' : '',
  48. $name
  49. );
  50. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<label>メーカー</label>
<select name="maker">
<option value="" selected>なし</option>
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</select>
<label>タイプ</label>
<label class="checkbox inline">
<input type="checkbox" name="sol[]" value="d">D</option>
</label>
<label class="checkbox inline">
<input type="checkbox" name="sol[]" value="e" checked>E</option>
</label>
<label class="checkbox inline">
<input type="checkbox" name="sol[]" value="f" checked>F</option>
</label>