Php uses a two-dimensional session array instance and a two-dimensional session array instance _ PHP Tutorial

Source: Internet
Author: User
Php uses two-dimensional session array instances and two-dimensional session array instances. Php uses a two-dimensional session array instance. session two-dimensional array instance this article describes how php uses a two-dimensional session array. Share it with you for your reference. The details are as follows: The most common php uses a two-dimensional session array instance and a two-dimensional session array instance.

This example describes how to use a two-dimensional array of session in php. Share it with you for your reference. The details are as follows:

The most common usage: a variable name

The code is as follows:

$ _ SESSION ['user'] = 0;
Echo $ _ SESSION ['user'];


Use arrays:

The code is as follows:

$ _ SESSION ['user'] ['A'] = 1;
$ _ SESSION ['user'] ['B'] = 2;
Echo $ _ SESSION ['user'] ['A'];
Echo $ _ SESSION ['user'] ['B'];


The advantage is that it can be grouped.

For example:

The code is as follows:

$ _ SESSION ['admin'] ['A'] = 11;
$ _ SESSION ['admin'] ['B'] = 22;

I hope this article will help you with PHP programming.


PHP's two-dimensional array in the session

Just give you an example. remember to add points directly ....

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']);
}
// The resulting $ data is similar to $ data = array (6 => array ('name' => 'A', 'price' => 100 ), 16 => array ('name' => 'BB ', 'price' => 102 ));

Session_register ("data ");
Echo "go B </a> ";
?>

B. php

Session_start ();
Print_r ($ HTTP_SESSION_VARS ['data']);
?>

Code writing is simple. haha.

[Tutorial, php] How does one understand the $ _ SESSION two-dimensional array?

$ _ SESSION ['cart'] [$ isbn] is a two-dimensional array, for example:
Cart represents a person's shopping cart,
$ Isbn indicates an item.
Now I am going to buy things. This cart represents me.
I bought a computer and a TV. $ isbn represents a computer or TV, either a computer or a TV, it depends on the value Passed in $ _ POST ["save.
If it is a computer, $ _ SESSION ['cart'] [$ isbn] = "computer ".

The example in this article describes how to use a two-dimensional array of session in php. Share it with you for your reference. The details are as follows: The most common...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.