Posted By

rodrigo on 11/19/08


Tagged

calendar google dates hours manage


Versions (?)

Managing multiple hours


 / Published in: PHP
 

URL: http://labs.reactor.cl

  1. $hours_from = array(
  2. '19:00',
  3. '21:00',
  4. '23:00'
  5. );
  6.  
  7. $hours_to = array(
  8. '20:00',
  9. '22:00',
  10. '24:00'
  11. );
  12.  
  13. $hours = array();
  14.  
  15. if(count($hours_from) == count($hours_to))
  16. {
  17. $hours_from = array_slice($hours_from, 1);
  18. $hours_to = array_slice($hours_to, 1);
  19.  
  20. for($i=0; $i<count($hours_from); $i++) {
  21. $hour_from = $hours_from[$i];
  22. $hour_to = $hours_to[$i];
  23.  
  24. if(! empty($hour_from) && ! empty($hour_to)) {
  25. $hours[$i] = $hour_from.' - '.$hour_to;
  26. }
  27. }
  28. }
  29.  
  30. $hours = implode(', ', $hours);
  31.  
  32. print $hours; // 21:00 - 22:00, 23:00 - 24:00

Report this snippet  

You need to login to post a comment.