按预期从数组打印不同的值

时间:2018-07-18 10:08:44

标签: php jquery json ajax

错误:当我在config.php上打印$ myconfig数组时,它会打印一个不同的值。仅关注[main_url],当在config.php上运行时其值会更改

myconfig.php

<?php
        $base_url = $_POST['base_url'];
        if($base_url == ""){
            $url=((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"). "://". @$_SERVER['HTTP_HOST']."/football/responsive_filemanager";
        }else{
            $url=$base_url;
        }   
        echo $base_url."</br>";
        echo $url;

        $myconfig=array(

            'main_url'=>$url,

            'upload_dir' => '/source/',

            'current_path' => '../source/',

            'thumbs_base_path' => '../thumbs/',

            'multiple_selection' => false,

            'multiple_selection_action_button' => false
        );
        //return $myconfig;
        /*echo "<pre>";*/
        //print_r($myconfig);
    ?>

myconfig.php的输出 enter image description here

config.php

<?php
     include("../../myconfig.php");
     print_r($myconfig);
     exit();
?>

config.php的输出 enter image description here

1 个答案:

答案 0 :(得分:1)

我认为您的情况不对。您要在条件之前将值设置为$base_url,因此它将始终在else语句中使用。因此,如果我不满意您的问题,则应将您的病情从$base_url == ""更改为$base_url !== ""

   if($base_url !== ""){
        $url=((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http"). "://". @$_SERVER['HTTP_HOST']."/football/responsive_filemanager";
    }
else{
        $url=$base_url;
    }