[英]How can i write key value pair in array in another php file
i have one phpfile let,xyz.php and from this file i have to update another phpfile let its name,abc.php 我有一个phpfile let,xyz.php,必须从这个文件中更新另一个phpfile,让它的名字abc.php
how can i do this to achieve my desired output. 我该怎么做才能达到我想要的输出。
xyz.php xyz.php
<?php
//need code for update $GLOBALS['app_list_strings']['ip_list'] array present in xyz.php
?>
abc.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
);
?>
Within xyz.php
, use require
or include
to access the variables defined in abc.php
在
xyz.php
,使用require
或include
访问abc.php
定义的变量。
<?php
require 'abc.php';
echo $GLOBALS['app_list_strings']['ip_list']['192.168.1.51']; // "server1"
The variable $_GLOBAL is not necessary. 不需要变量$ _GLOBAL。 You can also use:
您还可以使用:
return array();
and 和
$data = require '../path/to/my/file.php';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.