|
Posted by ..::MARIO::.. on 10/06/19 11:48
I modify the //call section with that:
echo "<table align=center border=1 width=300>\n";
echo "<tr bgcolor=lightgrey><td align=center><b>End time + (quantity *
time)</b></td></tr>";
foreach(jit($dates, $times, $quantity) as $result) {
echo "<tr><td align=center>".$result."</td></tr>\n";
}
echo "<tr><td align=center><b>It's gooooood ;)</b></td></tr>";
echo "</table>";
And all is ok.
Thanx Sandy, you are The Best for me.
Uzytkownik "Sandy" <sandeep22@gmail.com> napisal w wiadomosci
news:1148388461.391089.157600@g10g2000cwb.googlegroups.com...
> 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]
|