Return to Snippet

Revision: 9744
at November 19, 2008 15:06 by rodrigo


Initial Code
$hours_from = array(
	'19:00',
	'21:00',
        '23:00'
);

$hours_to = array(
	'20:00',
	'22:00',
        '24:00'
);

$hours = array();

if(count($hours_from) == count($hours_to))
{
	$hours_from = array_slice($hours_from, 1);
	$hours_to   = array_slice($hours_to, 1);
	
	for($i=0; $i<count($hours_from); $i++) {
		$hour_from = $hours_from[$i];
		$hour_to   = $hours_to[$i];
		
		if(! empty($hour_from) && ! empty($hour_to)) {
			$hours[$i] = $hour_from.' - '.$hour_to;
		}
	}
}	

$hours = implode(', ', $hours);

print $hours; // 21:00 - 22:00, 23:00 - 24:00

Initial URL
http://labs.reactor.cl

Initial Description


Initial Title
Managing multiple hours

Initial Tags
google

Initial Language
PHP