I have a php file that contains an array $myArray.
<?php
$myArray = array(
'key1'=>'value1',
'key2'=>'value2',
);
?>
I need to read the value of key1 from that array. Is there a way to directly read key1, without including the whole file? Right now I’m using include like this.
$includedArray = include('/path/to/myArray.php');
but this is creating a problem for me, because even though I include it under a new name $includedArray, it still recognizes the old name $myArray which causes naming conflicts.
To solve this problem, I would have changed the included array from a named array ($myArray) to an un-named array, but I can’t make changes to the included files. So is there a way to either:
-
include the file containing the named array, but have it completely forget the original name (
$myArray), and have it use ONLY the new name I give it ($includedArray)? -
or is there a way to simply read 1 key from the array without including the whole file?
Then copy the array to another variable and unset the original array?
path/to/myNewArray.php:
usage: