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...