How to load return array from a PHP file?

bman picture bman · Aug 16, 2011 · Viewed 74.1k times · Source

I have a PHP file a configuration file coming from a Yii message translation file which contains this:

<?php
 return array(
  'key' => 'value'
  'key2' => 'value'
 );
?>

I want to load this array from another file and store it in a variable

I tried to do this but it doesn't work

function fetchArray($in)
{
   include("$in");
}

$in is the filename of the PHP file

Any thoughts how to do this?

Answer

Phil picture Phil · Aug 16, 2011

When an included file returns something, you may simply assign it to a variable

$myArray = include $in;

See http://php.net/manual/function.include.php#example-126