问题
i have one phpfile let,xyz.php and from this file i have to update another phpfile let its name,abc.php
how can i do this to achieve my desired output.
xyz.php
<?php
//need code for update $GLOBALS['app_list_strings']['ip_list'] array present in xyz.php
?>
abc.php
$GLOBALS['app_list_strings']['ip_list']=array (
'192.168.1.51' => 'server1',
// i have to add key and value pair here just like above from xyz.php
);
?>
回答1:
Within xyz.php, use require or include to access the variables defined in abc.php
<?php
require 'abc.php';
echo $GLOBALS['app_list_strings']['ip_list']['192.168.1.51']; // "server1"
回答2:
The variable $_GLOBAL is not necessary. You can also use:
return array();
and
$data = require '../path/to/my/file.php';
来源:https://stackoverflow.com/questions/17312874/how-can-i-write-key-value-pair-in-array-in-another-php-file