包含文件和函数PHP

时间:2014-01-30 10:56:33

标签: php

我有2个php文件file1.php和一些全局变量

file2.php有几个函数在某些x条件之后更改files1变量值。

file1.php包含file2.php的唯一问题是不回显/返回值。代码如下:

file1.php

 if ($result) {
    if ($result['image'] && file_exists(RC_UPLOADS_DIR . "vehicle_" . $result['image'])) {
        $image = RC_UPLOADS_URL . 'vehicle_' . $result['image'];
        $image_thumb = RC_UPLOADS_URL . 'cache/' . rc_image_resize(RC_UPLOADS_DIR . "vehicle_" . $result['image'], 160, 120);
    } else {
        $image = '';
        $image_thumb = '';
    }   
    $description = preg_replace(array("/\s\s/", "/\r\r/", "/\n\n/"), '<br />', trim($result['description']));

    $vehicle_meta = rc_getVehicleMeta($vehicle_id);
    global $GeneralPrice, $discount_price, $rent, $rent1, $rent2, $rent3,$rent4, $rent5, $rent6, $rent7, $rent8, $rent9, $rent10, $rent11, $rent12, $rent13, $rent14, $rent15, $rent16, $rent17, $rent18, $rent19, $rent20, $rent21, $rent22, $rent23, $rent24, $rent25, $rent26, $rent27, $rent28, $rent29, $rent30, $rent31, $rent32, $rent33, $rent34, $rent35, $rent36;


         $rent = $result['rent'];
         $rent1 = $vehicle_meta['rent1'];
         $rent2 = $vehicle_meta['rent2'];
         $rent3 = $vehicle_meta['rent3'];
         $rent4 = $vehicle_meta['rent4'];
         $rent5 = $vehicle_meta['rent5'];
         $rent6 = $vehicle_meta['rent6'];
         $rent7 = $vehicle_meta['rent7'];
         $rent8 = $vehicle_meta['rent8'];
         $rent9 = $vehicle_meta['rent9'];
         $rent10 = $vehicle_meta['rent10'];
         $rent11 = $vehicle_meta['rent11'];
         $rent12 = $vehicle_meta['rent12'];
         $rent13 = $vehicle_meta['rent13'];
         $rent14 = $vehicle_meta['rent14'];
         $rent15 = $vehicle_meta['rent15'];
         $rent16 = $vehicle_meta['rent16'];
         $rent17 = $vehicle_meta['rent17'];
         $rent18 = $vehicle_meta['rent18'];
         $rent19 = $vehicle_meta['rent19'];
         $rent20 = $vehicle_meta['rent20'];
         $rent21 = $vehicle_meta['rent21'];
         $rent22 = $vehicle_meta['rent22'];
         $rent23 = $vehicle_meta['rent23'];
         $rent24 = $vehicle_meta['rent24'];
         $rent25 = $vehicle_meta['rent25'];
         $rent26 = $vehicle_meta['rent26'];
         $rent27 = $vehicle_meta['rent27'];
         $rent28 = $vehicle_meta['rent28'];
         $rent29 = $vehicle_meta['rent29'];
         $rent30 = $vehicle_meta['rent30'];
         $rent31 = $vehicle_meta['rent31'];
         $rent32 = $vehicle_meta['rent32'];
         $rent33 = $vehicle_meta['rent33'];
         $rent34 = $vehicle_meta['rent34'];
         $rent35 = $vehicle_meta['rent35'];
         $rent36 = $vehicle_meta['rent36'];

        include_once('files2.php');



    $vehicle = array(
        'vehicle_id'    => $result['vehicle_id'],
        'title'         => $result['manufacturer']." ".$result['series'],
        'manufacturer'  => $result['manufacturer'],
        'series'        => $result['series'],
        'year'          => $result['year'],
        'class'         => $result['class'],
        'image'         => $image,
        'image_thumb'   => $image_thumb,
        'description'   => $description,
        'seats'         => $vehicle_meta['seats'],
        'doors'         => $vehicle_meta['doors'],
        'baggages'         => $vehicle_meta['baggages'],
        'conditioning'  => $vehicle_meta['conditioning'],
        'transmission'  => $vehicle_meta['transmission'],
        'total_price'     => $rc_currency->format((($rental_days*$GeneralPrice )-($rental_days*$GeneralPrice)* ($discount_price)/100)+ $total_extras),
        'total_price_return_fee'     => $rc_currency->format((($rental_days*$GeneralPrice)-($rental_days*$GeneralPrice)* ($discount_price)/100)+ $xfee + $total_extras),
        'total_price_return_fee'     => $rc_currency->format((($rental_days*$GeneralPrice)-($rental_days*$GeneralPrice)* ($discount_price)/100)+ $xfee2 + $total_extras),
        'daily_price'     => $rc_currency->format((($GeneralPrice)-($GeneralPrice)* ($discount_price)/100)+ $excess_price),
        'daily_price_return_fee'     => $rc_currency->format((($GeneralPrice)-($GeneralPrice)* ($discount_price)/100)+ ( $xfee / $rental_days)),
        'daily_price_return_fee2'     => $rc_currency->format((($GeneralPrice)-($GeneralPrice)*($discount_price)/100)+ ( $xfee2 / $rental_days))


    );

}

return $vehicle;
}

File2.php

<?php
//Out of Season function

function outofseason(){
global $rental_days, $GeneralPrice, $discount_price, $days1,$discount1, $days2, $discount2, $days3, $discount3, $rent;
//Discount with Duration
$days1 = get_field('days');
$discount1 = get_field('discount_days1');
$days2 = get_field('days2');
$discount2 = get_field('discount_days2');
$days3 = get_field('days3');
$discount3 = get_field('discount_days3');
$GeneralPrice = $rent;

if($rental_days > $days1 && $rental_days < $days2){
return $discount_price = $discount1;
}elseif($rental_days > $days2 && $rental_days < $days3){
return $discount_price = $discount1 + $discount2;
}elseif($rental_days > $days3 && $discount3 !=0){
return $discount_price = $discount1 + $discount2 + $discount3;

}else{
return $discount_price = 0;
    }   
}


//Seasons

function Seasonlow() {
global $rental_days, $GeneralPrice, $discount_price, $season_start_date_low, $season_end_date_low, $rent1, $rent2, $rent3, $rent4, $rent5, $rent6, $rent7, $rent8, $rent9;

//Date calculator
$datetime1 = '2014-02-05';
$datetime2 = '2014-04-15';
$duration = 86400 ;
$days_dur = ceil(strtotime($datetime2)-strtotime($datetime1))/$duration;


//$season_start_date_low = '05/02/2014';
//$season_end_date_low = '15/02/2014';
$pickupdate = $_GET['pickup_date'];
$returndate = $_GET['return_date'];

//if($pickupdate >= $season_start_date_low && $returndate <= $season_end_date_low){

if($rental_days  == 1){
    return $GeneralPrice = $rent1;
    $discount_price = 0;
    }elseif($rental_days == 2){
        return $GeneralPrice = $rent2;
         $discount_price = 0;
    }elseif($rental_days == 3){
        return $GeneralPrice = $rent3;
         $discount_price = 0;
    }elseif($rental_days == 4){
        return $GeneralPrice = $rent4;
         $discount_price = 0;
    }elseif($rental_days == 5){
        return $GeneralPrice = $rent5;
         $discount_price = 0;
    }elseif($rental_days == 6){
        return $GeneralPrice = $rent6;
         $discount_price = 0;
    }elseif($rental_days >= 7 && $rental_days <= 13){
        return $GeneralPrice = $rent7;
         $discount_price = 0;
    }elseif($rental_days >= 14 && $rental_days <= 20){
        return $GeneralPrice = $rent8;
         $discount_price = 0;
    }elseif($rental_days >= 21){
        return $GeneralPrice = $rent9;
         $discount_price = 0;
    }
//}else {
    //outofseason();
    //}

}


//Season Mid
function Seasonmid() {
global $rental_days, $GeneralPrice, $discount_price, $season_start_date_mid, $season_end_date_mid, $rent10, $rent11, $rent12, $rent13, $rent14, $rent15, $rent16, $rent17, $rent18;

//Date calculator
$datetime1 = '2014-02-05';
$datetime2 = '2014-04-15';
$duration = 86400 ;
$days_dur = ceil(strtotime($datetime2)-strtotime($datetime1))/$duration;


//$season_start_date_mid = '05/03/2014';
//$season_end_date_mid = '15/03/2014';
$pickupdate = $_GET['pickup_date'];
$returndate = $_GET['return_date'];

//if($pickupdate >= $season_start_date_mid && $returndate <= $season_end_date_mid){

if($rental_days  == 1){
    return $GeneralPrice = $rent10;
    $discount_price = 0;
    }elseif($rental_days == 2){
        return $GeneralPrice = $rent11;
         $discount_price = 0;
    }elseif($rental_days == 3){
        return $GeneralPrice = $rent12;
         $discount_price = 0;
    }elseif($rental_days == 4){
        return $GeneralPrice = $rent13;
         $discount_price = 0;
    }elseif($rental_days == 5){
        return $GeneralPrice = $rent14;
         $discount_price = 0;
    }elseif($rental_days == 6){
        return $GeneralPrice = $rent15;
         $discount_price = 0;
    }elseif($rental_days >= 7 && $rental_days <= 13){
        return $GeneralPrice = $rent16;
         $discount_price = 0;
    }elseif($rental_days >= 14 && $rental_days <= 20){
        return $GeneralPrice = $rent17;
         $discount_price = 0;
    }elseif($rental_days >= 21){
        return $GeneralPrice = $rent18;
         $discount_price = 0;
    }
//}else {
    //  outofseason();
    //}

}

//Season Mid_B
function Seasonmid_B() {
global $rental_days, $GeneralPrice, $discount_price, $season_start_date_mid_B, $season_end_date_mid_B, $rent19, $rent20, $rent21, $rent22, $rent23, $rent24, $rent25, $rent26, $rent27;

//Date calculator
$datetime1 = '2014-02-05';
$datetime2 = '2014-04-15';
$duration = 86400 ;
$days_dur = ceil(strtotime($datetime2)-strtotime($datetime1))/$duration;


//$season_start_date_mid = '05/03/2014';
//$season_end_date_mid = '15/03/2014';
$pickupdate = $_GET['pickup_date'];
$returndate = $_GET['return_date'];

//if($pickupdate >= $season_start_date_mid && $returndate <= $season_end_date_mid){

if($rental_days  == 1){
    return $GeneralPrice = $rent19;
     $discount_price = 0;
    }elseif($rental_days == 2){
        return $GeneralPrice = $rent20;
         $discount_price = 0;
    }elseif($rental_days == 3){
        return $GeneralPrice = $rent21;
         $discount_price = 0;
    }elseif($rental_days == 4){
        return $GeneralPrice = $rent22;
         $discount_price = 0;
    }elseif($rental_days == 5){
        return $GeneralPrice = $rent23;
         $discount_price = 0;
    }elseif($rental_days == 6){
        return $GeneralPrice = $rent24;
         $discount_price = 0;
    }elseif($rental_days >= 7 && $rental_days <= 13){
        return $GeneralPrice = $rent25;
         $discount_price = 0;
    }elseif($rental_days >= 14 && $rental_days <= 20){
        return $GeneralPrice = $rent26;
         $discount_price = 0;
    }elseif($rental_days >= 21){
        return $GeneralPrice = $rent27;
         $discount_price = 0;
    }
//}else {
    //  outofseason();
    //}

 }

    //Season Mid_B
    function SeasonHigh() {
global $rental_days, $GeneralPrice, $discount_price, $season_start_date_mid_high, $season_end_date_high, $rent28, $rent29, $rent30, $rent31, $rent32, $rent33, $rent34,  $rent35, $rent36;

//Date calculator
$datetime1 = '2014-02-05';
$datetime2 = '2014-04-15';
$duration = 86400 ;
$days_dur = ceil(strtotime($datetime2)-strtotime($datetime1))/$duration;


//$season_start_date_mid = '05/03/2014';
//$season_end_date_mid = '15/03/2014';
$pickupdate = $_GET['pickup_date'];
$returndate = $_GET['return_date'];

//if($pickupdate >= $season_start_date_mid && $returndate <= $season_end_date_mid){

if($rental_days  == 1){
    return $GeneralPrice = $rent28;
     $discount_price = 0;
    }elseif($rental_days == 2){
        return $GeneralPrice = $rent29;
         $discount_price = 0;
    }elseif($rental_days == 3){
        return $GeneralPrice = $rent30;
         $discount_price = 0;
    }elseif($rental_days == 4){
        return $GeneralPrice = $rent31;
         $discount_price = 0;
    }elseif($rental_days == 5){
        return $GeneralPrice = $rent32;
         $discount_price = 0;
    }elseif($rental_days == 6){
        return $GeneralPrice = $rent33;
         $discount_price = 0;
    }elseif($rental_days >= 7 && $rental_days <= 13){
        return $GeneralPrice = $rent34;
         $discount_price = 0;
    }elseif($rental_days >= 14 && $rental_days <= 20){
        return $GeneralPrice = $rent35;
         $discount_price = 0;
    }elseif($rental_days >= 21){
        return $GeneralPrice = $rent36;
         $discount_price = 0;
    }
//}else {
    //  outofseason();
    //}

}
//low

$season_start_date_low = (get_option('rc_settings_season_start_date_low'));
$season_end_date_low = (get_option('rc_settings_season_end_date_low'));

$season_start_date_low_convert = str_replace('/', '-', $season_start_date_low);
$season_low_start = date('Y-m-d', strtotime($season_start_date_low_convert));

$season_end_date_low_convert = str_replace('/', '-', $season_end_date_low);
$season_low_end = date('Y-m-d', strtotime($season_end_date_low_convert));

//mid
$season_start_date_mid = get_option('rc_settings_season_start_date_mid');
$season_end_date_mid = get_option('rc_settings_season_end_date_mid');
$season_start_date_mid_B = get_option('rc_settings_season_start_date_mid_B');
$season_end_date_mid_B = get_option('rc_settings_season_end_date_mid_B');

$season_start_date_mid_convert = str_replace('/', '-', $season_start_date_mid);
$season_mid_start = date('Y-m-d', strtotime($season_start_date_mid_convert));

$season_end_date_mid_convert = str_replace('/', '-', $season_end_date_mid);
$season_mid_end = date('Y-m-d', strtotime($season_end_date_mid_convert));

$season_start_date_mid_B_convert = str_replace('/', '-', $season_start_date_mid_B);
$season_mid_B_start = date('Y-m-d', strtotime($season_start_date_mid_B_convert));

$season_end_date_mid_B_convert = str_replace('/', '-', $season_end_date_mid_B);
$season_mid_B_end = date('Y-m-d', strtotime($season_end_date_mid_B_convert));

//High
$season_start_date_high = get_option('rc_settings_season_start_date_high');
$season_end_date_high = get_option('rc_settings_season_end_date_high');

$season_start_date_high_convert = str_replace('/', '-', $season_start_date_high);
$season_high_start = date('Y-m-d', strtotime($season_start_date_high_convert));

$season_end_date_high_convert = str_replace('/', '-', $season_end_date_high);
$season_high_end = date('Y-m-d', strtotime($season_end_date_high_convert));


//Date calculator
//$datetime1 = '01/01/2014';
//$datetime2 = '04/02/2014';
//$duration = 86400 ;
//$days_dur = ceil(strtotime($season_start_date_low)-     strtotime($season_end_date_low))/$duration;


//Dates Conversion
$pickupdate_final = $_GET['pickup_date'];
$pickupdate_final_convert = str_replace('/', '-', $pickupdate_final);
$pickup_dates = date('Y-m-d', strtotime($pickupdate_final_convert));

$returndate_final = $_GET['return_date'];
$returndate_final_convert = str_replace('/', '-', $returndate_final);
$return_dates = date('Y-m-d', strtotime($returndate_final_convert));

//Conditions
if($pickup_dates >= $season_low_start && $return_dates <= $season_low_end){
Seasonlow();
echo "low  <br />";
}elseif($pickup_dates >= $season_mid_start && $return_dates <= $season_mid_end){
Seasonmid();
echo "mid  <br />";
}elseif($pickup_dates >= $season_mid_B_start && $return_dates <= $season_mid_B_end){
Seasonmid_B();
echo "mid_B  <br />";
}elseif($pickup_dates >= $season_high_start && $return_dates <= $season_high_end){
SeasonHigh();
echo "High  <br />";
}else{
outofseason();
echo "out <br />";
}

?>

1 个答案:

答案 0 :(得分:1)

include_once('files2.php');

应该是:

include_once('file2.php');