Home > Backend Development > PHP Tutorial > 基本语法 怎么往SESSION数组里添加元素

基本语法 怎么往SESSION数组里添加元素

WBOY
Release: 2016-06-13 12:21:21
Original
1110 people have browsed it

基本语法 如何往SESSION数组里添加元素
问一个很弱的基本语法。
如果是普通数组,我们可以这样:

<br />$arr=array();<br />$arr[]="1";<br />$arr[]="2";<br />print_r($arr);<br />//这样就可以实现为$arr数组添加元素的目的<br />
Copy after login


问题是,如果我定义的是一个SESSION数组:
<br />$_SESSION['a']=array();<br />//我要往$_SESSION['a']数组里添加1,2两个元素,应该怎么表示?<br />
Copy after login

------解决思路----------------------
$a=array("a","b");<br />$_SESSION["a"]=$a;  <br />print_r($_SESSION["a"]);
Copy after login

------解决思路----------------------
有什么区别吗?
$_SESSION['a'][] = 1;<br />$_SESSION['a'][] = 2;
Copy after login

------解决思路----------------------

$_SESSION['a']=array();
$_SESSION['a'][] = 1;<br />$_SESSION['a'][] = 2;
Copy after login

------解决思路----------------------
$_SESSION['a'][]=1;<br />$_SESSION['a'][]=2;
Copy after login

------解决思路----------------------
你这就是二维数组了 在后面继续追加中括号就行
------解决思路----------------------
$_SESSION['a'][]="xxx"

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template