|
Posted by Sandy on 10/14/61 11:48
Hi Mario, i hope the function below sorts out ur problem.. just
substitute your values in the initialisation of the three arrays at the
bottom..
<?
/*
* @author : Sandeep Singh
*/
function jit($dates, $times, $quantity) {
if(!is_array($dates) || !is_array($times) || !is_array($quantity)) {
exit('Invalid arguments');
}
//sort the dates
array_walk($dates, 'convertArray', 'date');
sort($dates);
//sort the time
array_walk($times, 'convertArray', 'time');
sort($times);
sort($quantity);
$jitValue = array();
foreach($dates as $key=>$date) {
$jitValue[date('Y-m-d', $date)] = $date+$quantity[$key]*$times[$key];
}
return $jitValue;
}
function convertArray(&$item1, $key, $param) {
//convert to UNIX timestamp
if($param == 'date') {
$item1 = strtotime($item1);
}
else if($param == 'time'){
//try to strip the 'sec' part
$item1 = preg_replace('/[A-z]+/', '', $item1);
}
}
//initialize the array..
$dates = array('2006-01-01', '2006-02-05', '2006-10-15');
$times = array('20sec', '50sec', '45sec');
$quantity = array(200, 300, 240);
//call
$jitValue = jit($dates, $times, $quantity);
echo '<pre>';
print_r($jitValue)
?>
[Back to original message]
|