Guest User

Untitled

a guest
Jan 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. foreach($result as $r){
  2. foreach($ids_time as $time){
  3. if($r['id_time'] == $time['id']){
  4. $row[] = $r;
  5. }
  6. }
  7. }
  8.  
  9. [0] => Array
  10. (
  11. [id] => 93
  12. [date] => 2017-03-31
  13. )
  14.  
  15. [0] => Array
  16. (
  17. [id] => 22
  18. [id_time] => 93
  19. [id_client] => 69
  20. )
  21.  
  22. function arr_index($arr, $key) {
  23. $result = [];
  24. foreach ($arr as $item) {
  25. if (isset($item[$key])) {
  26. $result[$item[$key]] = $item;
  27. }
  28. }
  29.  
  30. return $result;
  31. }
  32.  
  33. $indexed_time = arr_index($ids_time, 'id');
  34. $row = array_map(function($item) use($indexed_time) {
  35. return $indexed_time[$item['time_id']] ?? null;
  36. }, $result);
  37.  
  38. $timesId = [];
  39. foreach ($ids_time as $time) {
  40. $timesId[$time['id']] = $time['id'];
  41. }
  42. foreach ($result as $r) {
  43. if (!empty($timesId[$r['id_time']])) {
  44. $row[] = $r;
  45. }
  46. }
Add Comment
Please, Sign In to add comment