如何将数组存储到PHP中的会话变量 [英] How to store an array into a session variable in php

查看:129
本文介绍了如何将数组存储到PHP中的会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//返回10从问题表的问题。

//Returns 10 question from questions table

$result = mysqli_query($con,"SELECT question FROM questions ORDER BY rand() LIMIT 10' ");
while($row = mysqli_fetch_row($result))
{
$que[]=$row[0];
}  

现在我需要这个一整套 $阙[] 的存储在一个会话变量。 (即10题)

Now I need to store this whole set of $que[] in a session variable. (i.e 10 questions)

像这样

$_SESSION['question'] = $que[]; 

$my_array[] = $_SESSION['question'];

$ my_array [0] 返回的第一个问题, $ my_array [1] 返回第二个问题,而像那。

so that $my_array[0] returns first question, $my_array[1] returns second questions and like that.

(感谢名单提前为帮助)

(Thanx for the help in advance)

推荐答案

分配

$_SESSION['question'] = $que; 

的print_r($ _ SESSION ['问题'] [0]); 会给你的第一个问题。

这篇关于如何将数组存储到PHP中的会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆