search
Homephp教程php手册php使用session二维数组实例,session二维数组实例

php使用session二维数组实例,session二维数组实例

本文实例讲述了php使用session二维数组的用法。分享给大家供大家参考。具体如下:

最普通的用法:一个变量名

复制代码 代码如下:

$_SESSION['user'] = 0;
echo $_SESSION['user'];


使用数组:

复制代码 代码如下:

$_SESSION['user']['a'] = 1;
$_SESSION['user']['b'] = 2;
echo $_SESSION['user']['a'];
echo $_SESSION['user']['b'];


这样的好处是可以分组。
 
如可以使用:

复制代码 代码如下:

$_SESSION['admin']['a'] = 11;
$_SESSION['admin']['b'] = 22;

希望本文所述对大家的PHP程序设计有所帮助。

PHP关於session中的二维数组

直接给你上例子吧.记得要直接加分哦....

a.php


session_start();

$sql = "SELECT * FROM [TABLE] WHERE ..";
$data=array();
$query = mysql_query( $sql , $link );
while($row=mysql_fetch_array($query, MYSQL_ASSOC )){
$data[$row['id']] = array('name' => $row['name'] , 'price' => $row['price']);
}
//此时得到的$data类似于$data=array( 6 => array('name' => 'aa','price' => 100 ) , 16 => array('name' => 'bb','price' => 102 ) );

session_register("data");
echo "go b";
?>

b.php


session_start();
print_r($HTTP_SESSION_VARS['data']);
?>

代码写的很简单.哈哈.
 

【教,php】这个$_SESSION二维数组怎理解?

$_SESSION['cart'][$isbn]是二维数组,比如:
cart代表某个人的购物车,
$isbn代表是物品。
现在我去买东西,这个cart代表的是我.
我买了一台电脑,一台电视,$isbn就代表是电脑或者是电视,具体是电脑还是电视,那就要看$_POST["save"]传过来的值了。
如果传过来的是电脑那么$_SESSION['cart'][$isbn]="电脑".
 

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),