php : test for lines of array the condition range of date is between range of date -
i have logic problem on how filter entries within range of date.
an array $price
contains prices flight depending of period of travel, ordered date:
print_r($price) [21] => array [date_beg] => 2014-07-05 [total1] => 648 [22] => array [date_beg] => 2014-08-05 [total1] => 750 [23] => array [date_beg] => 2014-08-12 [total1] => 520
it 648 euros 2014-08-05, becomes 750 2014-08-05 ...
i have special offers @ periods.
the same information present each element of array:
print_r($price) [21] => array [date_beg] => 2014-07-05 [total1] => 648 [special_beg] => 2014-07-07 [special_end] => 2014-08-06 [special_price] => 600 [22] => array [date_beg] => 2014-08-05 [total1] => 750 [special_beg] => 2013-10-27 [special_end] => 2013-12-18 [special_price] => 600 [23] => array [date_beg] => 2014-08-12 [total1] => 520 [special_beg] => 2013-10-27 [special_end] => 2013-12-18 [special_price] => 600
what feeding new "display" array containing details of special price each element of array promotion valid for.
something like:
$nb_date=0; foreach($price $a_price){ if (($a_price['special_beg']>$a_price['date_beg'])) //+ other conditions { $display[$nb_date]'special_beg']=$a_price['special_beg']; $display[$nb_date]'special_end']=$a_price['special_end']; $display[$nb_date]'special_price']=$a_price['special_price']; $display[$nb_date]'promo_web']=$a_price['promo_web']; $display[$nb_date]['promo_text']=$a_price['promo_text']; ...etc... } $nb_date++; }
i have tried quite few things no success.
i use datetime convert date string date object. otherwise >
operator working on 2 strings , strings compared differently dates do. there may better way...
$nb_date=0; //make sure set default timezone when working datetime class //set list: http://www.php.net/manual/en/timezones.php date_default_timezone_set('america/new_york'); //datetime object current date/time $now = new datetime(); foreach($price $a_price){ //i *think* logic want, making sure current //date after beginning date. $date_beg = new datetime($a_price['date_beg']); if ( $now > date_beg ){ $display[$nb_date]['special_beg']=$a_price['special_beg']; ... } $nb_date++; }
Comments
Post a Comment