sebuahhobi

implode explode multiselect

Oct 25th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //helper
  2. //kondisi kamar
  3. function kondisi($name, $table, $field, $id_kamar, $selected, $hitung) {
  4. $ci = get_instance();
  5. $cmb = "<select id='$name' name='kondisi[]' class='select2_multiple form-control' multiple='multiple'>";
  6. $cmb .= "<option value=''>--Pilih--</option>";
  7. $ci->db->order_by($field,'ASC');
  8. $data = $ci->db->get($table)->result();
  9. $a=0;
  10. foreach ($data as $d) {
  11. $cmb .="<option value='" . $d->$field . "'";
  12. //$cmb .=set_select('perlengkapan', $d->$field);
  13. $cmb .= $selected[$a] == $d->$field ? " selected='selected'" : '';
  14. $cmb .=">" . strtoupper($d->$field) . "</option>";
  15.  
  16. if($a<3){
  17. $a++;
  18. }
  19. }
  20. $cmb .="</select>";
  21.  
  22. return $cmb;
  23. }
  24.  
  25.  
  26. //view
  27. <?php
  28. $kondisi = Array ( [0] => AC Bagus [1] => Atap Bagus [2] => Kursi Bagus )
  29.  
  30. function split_nth($str, $delim, $n)
  31. {
  32. return array_map(function($p) use ($delim) {
  33. return implode($delim, $p);
  34. }, array_chunk(explode($delim, $str), $n));
  35. }
  36. $array = split_nth($kondisi, " ", 2);
  37.  
  38. echo kondisi('kondisi', 'status_kamar', 'kondisi', 'id', $array);
  39. ?>
Add Comment
Please, Sign In to add comment