1

我目前坚持我认为是一个简单的解决方案......我正在使用 PHPFileNavigator,我唯一坚持的是如何回显返回到单独文件上的数组的标题. 每次为上传的文件创建/编辑文件时,当为文件添加标题时,它会在下面生成以下文件。

更新

一般来说,我想要做的就是从我的目标文件中返回一个数组值,在这种情况下,它将来自“titulo”键,然后将它打印回我的源文件。

目标文件

 <?php
 defined('OK') or die();
 return array(
    'titulo' => 'Annual 2011 Report',
    'usuario' => 'admin'
 );
 ?>

源文件

<?php
  $filepath="where_my_destination_file_sits";
  define('OK', True); $c = include_once($filepath); print_r($c);
?>

当前结果

Array ( [titulo] => Annual 2011 Report [usuario] => admin )

提议的结果

Annual 2011 Report

我只想知道如何将此数组回显到另一个 PHP 页面上的变量中?提前致谢。

4

4 回答 4

3

假设您的文件保存在$filepath

<?php
define('OK', True);
$c = include_once($filepath);
print_r($c);
于 2012-09-04T05:38:03.400 回答
1

If you know the file name and file path, you can easily capture the returned construct of the php file, to a file.

Here is an example:

$filepath = 'path/to/phpfile.php';
$array = include($filepath); //This will capture the array
var_dump($array);

Another example of include and return working together: [Source: php.net]

return.php

<?php

$var = 'PHP';

return $var;

?>

noreturn.php

<?php

$var = 'PHP';

?>

testreturns.php

<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>

Update

To only print a item from the array, you can use the indices. In your case:

<?php

$filepath="where_my_destination_file_sits";

define('OK', True); $c = include_once($filepath); print_r($c);
echo $c['titulo']; // print only the title

?>
于 2012-09-04T05:45:09.123 回答
0

首先我们有一个文件(你想在其中初始化数组)first.php

(你也可以更专业地玩参数,任何参数函数传递不同的类型或不同的数组)

 function first_passing() {
      $yourArray=array('everything you want it's be');
      return $yourArray;
     }

而在second.php

require 'yourpath/first.php' (or include or include_once or require_once )
//and here just call function
$myArray=first_passing();
//do anything want with $myArray
于 2012-09-04T05:58:03.063 回答
-1

To print/echo an array in PHP you have to use print_r($array_variable) and not echo $array

于 2012-09-04T05:39:54.247 回答