You are here: Re: Can somebody help me to write PHP function ? - Just in Time alghoritm. « PHP SQL « IT news, forums, messages
Re: Can somebody help me to write PHP function ? - Just in Time alghoritm.

Posted by Sandy on 09/26/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)
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация