Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有固定值的PHP数组_Php_Arrays_Static_Global Variables - Fatal编程技术网

具有固定值的PHP数组

具有固定值的PHP数组,php,arrays,static,global-variables,Php,Arrays,Static,Global Variables,有人能举个例子告诉我吗?有没有办法在PHP数组中永久(或直到我们重新启动服务器)存储变量 我听说过静态数组和全局变量之类的东西,但我不能把它们放在一起 $storearray = array(); array_push($storearray, "apple", "ball"); //in 30mins array_push($storearray, "land", "band"); //in 1 hour array_push($storearray, "bland", "aband");

有人能举个例子告诉我吗?有没有办法在PHP数组中永久(或直到我们重新启动服务器)存储变量

我听说过静态数组和全局变量之类的东西,但我不能把它们放在一起

$storearray = array();
array_push($storearray, "apple", "ball"); 
//in 30mins
array_push($storearray, "land", "band");
//in 1 hour
array_push($storearray, "bland", "aband");
当我选择数组时,我希望所有元素都在那里使用数据库:


示例:
MYSQL

如果要永久存储数据,必须将其保存到数据库或文件中。持久存储是通过数据库而不是全局变量完成的。“当我检查数组时,我希望所有元素都在那里”:有一种称为数据库的方法,您可以将数据存储到它们中,并在需要时检索数据。用户的数据库调用是昂贵的操作。。。这只是为了保存数据。。。就像在一次会议中保存一块饼干一样。@vivoconuxino:是的,那也是:停留。。如果他重新启动,我认为memcache可能会丢失数据,但不确定数据库调用是昂贵的操作。。。这只是为了保存数据。。。就像在会话中保存cookie一样。。。