|
Posted by ..::MARIO::.. on 10/14/97 11:48
Thanx so much.
I'm trying to use data from database instead of constant values.
I have only one question.
When i would like to save the data into database i must use FOR ()
statement, for extract data from Array ?
----- Original Message -----
From: "Sandy" <sandeep22@gmail.com>
Newsgroups: alt.php.sql
Sent: Tuesday, May 23, 2006 2:47 PM
Subject: Re: Can somebody help me to write PHP function ? - Just in Time
alghoritm.
> 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)
> ?>
>
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]
|