Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php文件中读取数组_Php_Arrays - Fatal编程技术网

从php文件中读取数组

从php文件中读取数组,php,arrays,Php,Arrays,我有一个PHP文件,但该文件的数据是数组 当我打开文件时,我可以获取其内容,但无法将其作为数组读取。它只是一根线。有没有办法将php文件读取为数组 我的php文件看起来像 <?php $someArray = array ( 0 => array ( 'data' => 'sadsa', 'sadsad' => 'sdsss', ...... 'DOB' => array ( 0 =>

我有一个PHP文件,但该文件的数据是数组

当我打开文件时,我可以获取其内容,但无法将其作为数组读取。它只是一根线。有没有办法将php文件读取为数组

我的php文件看起来像

<?php $someArray = array (
  0 => 
  array (
    'data' => 'sadsa',
    'sadsad' => 'sdsss',
    ...... 
    'DOB' => 
    array (
      0 => 
      array (
        'Day' => '12',
        'Month' => '12',
        'Year' => '12',
      ),
    ),
    ..
    ...
  ),
  1 => 
  ...........
  ...
  2 =>
  ...
  ....
现在我想读取文件并将其作为数组访问

您不需要
file\u get\u contents()
来实现您想要实现的目标,因为该文件包含一个声明的变量。您需要的是将文件包含在当前脚本中,并像在同一脚本中声明一样访问数组,如下所示。请记住,
file\u get\u contents()
将始终以字符串形式返回文件内容。理想情况下(在本例中),这不是您需要的


您不需要
file\u get\u contents()
来实现您想要实现的目标,因为该文件包含一个声明的变量。您需要的是将文件包含在当前脚本中,并像在同一脚本中声明一样访问数组,如下所示。请记住,
file\u get\u contents()
将始终以字符串形式返回文件内容。理想情况下(在本例中),这不是您需要的


您可以使用include函数作为数组加载整个文件,也可以使用require或include加载文件

数组文件

<?php return array (
  0 => 
  array (
    'data' => 'sadsa',
    'sadsad' => 'sdsss',
    ...... 
    'DOB' => 
    array (
      0 => 
      array (
        'Day' => '12',
        'Month' => '12',
        'Year' => '12',
      ),
    ),
    ..
    ...
  ),
  1 => 
  ...........
  ...
  2 =>
  ...
  ....
<?php
$someArray = include $filepath;

您可以使用include函数作为数组加载整个文件,也可以使用require或include加载文件

数组文件

<?php return array (
  0 => 
  array (
    'data' => 'sadsa',
    'sadsad' => 'sdsss',
    ...... 
    'DOB' => 
    array (
      0 => 
      array (
        'Day' => '12',
        'Month' => '12',
        'Year' => '12',
      ),
    ),
    ..
    ...
  ),
  1 => 
  ...........
  ...
  2 =>
  ...
  ....
<?php
$someArray = include $filepath;

你需要
包括
要求
或你拥有的东西。使用
包括
代替你需要
包括
要求
或你拥有的东西。改用
包括