如何推动新的数组值到一个PHP会话阵列? [英] How to push a new array value into a PHP session array?
本文介绍了如何推动新的数组值到一个PHP会话阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下粗略code:
I have the following rough code:
$_SESSION['ids'] = array('strawberry', 'banana', 'apple');
和要插入一个条件一些值(当用户点击一个某个按钮等)。
and want to insert some values on a condition (when a person clicks a certain button etc).
array_push($_SESSION['ids'], 'orange');
但它似乎不工作?
but it doesn't seem to work?
原来阵列'的草莓的','的香蕉的','的苹果的在那里当我查看的var_dump ED 查看它,而是'的橙色的',不是吗?
The original array with 'strawberry', 'banana', 'apple' are there when I view a var_dump'ed view of it, but 'orange' is not there?
推荐答案
我已经测试了以下code对PHP 5.4:
I have tested the following code on PHP 5.4:
session_start();
$_SESSION['ids'] = array('strawberry', 'banana', 'apple');
array_push($_SESSION['ids'], 'orange');
var_dump($_SESSION['ids']);
的输出如下所示:
The output is as follows:
array(1) { ["ids"]=> array(4) { [0]=> string(10) "strawberry" [1]=> string(6) "banana" [2]=> string(5) "apple" [3]=> string(6) "orange" } }
这篇关于如何推动新的数组值到一个PHP会话阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文