fork download
  1. <?php
  2.  
  3. $rs2 = [
  4. [
  5. "ID_Tag" => 1,
  6. "tag" => "PHP"
  7. ], [
  8. "ID_Tag" => 2,
  9. "tag" => "HTML"
  10. ], [
  11. "ID_Tag" => 3,
  12. "tag" => "MYSQL"
  13. ], [
  14. "ID_Tag" => 4,
  15. "tag" => "Designer de site"
  16. ]
  17. ];
  18.  
  19. $row3 = [
  20. "habilidades" => "PHP,HTML,Designer de site",
  21.  
  22. ];
  23.  
  24. $habilidades = explode(",", $row3['habilidades']);
  25.  
  26. foreach($rs2 as $row2) {
  27. $selected = in_array($row2['tag'], $habilidades) ? "selected" : "";
  28. echo "<option value='{$row2['ID_Tag']}' {$selected}>{$row2['tag']}</option>", PHP_EOL;
  29. }
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
<option value='1' selected>PHP</option>
<option value='2' selected>HTML</option>
<option value='3' >MYSQL</option>
<option value='4' selected>Designer de site</option>