How can i write key value pair in array in another php file

…衆ロ難τιáo~ 提交于 2019-12-12 05:37:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!