PHP。为什么包含文件中的 return 没有赋值给变量?

PHP. Why return in included file dosen't assign with variable?

例如我有2个文件:

//db.php
return array(
   'server'=>'localhost',
   'db'=>'mydb',
   'name'=>'root',
   'password'=>'root',
);

和第二个文件:

//index.php
$config = (include 'db.php');

之后 $config = 1 如果包含文件或 $config = 0 如果不包含文件,但 $config 必须是 array()db.php 文件中。

什么问题?

windows 7x64,阿帕奇 2.2,php5.4

您可以使用 INI 文件作为您的数据库凭据。不要忘记在 .htaccess 文件中拒绝对 config.ini 的访问。

config.ini

[database]
server = localhost
db = mydb
name = root
password = root

index.php

<?php
    $config = parse_ini_file('config.ini');

    // Access to credentials
    echo $config['server'];
?>

来自deceze的正确答案 短开标签!!! <? The array is not supposed to be output at all; if it is, something's wrong with your file. In this case, PHP isn't configured to handle short open tags