PHP uses session two-dimensional array instance, session two-dimensional array instance
This article describes the use of the session two-dimensional array of PHP. Share to everyone for your reference. Specific as follows:
The most common usage: a variable name
Copy the Code code as follows: $_session[' user '] = 0;
echo $_session[' user ';
Using arrays:
Copy the Code code as follows: $_session[' user ' [' a '] = 1;
$_session[' user ' [' b '] = 2;
echo $_session[' user ' [' a '];
echo $_session[' user ' [' B '];
The benefit is that it can be grouped.
If you can use:
Copy the Code code as follows: $_session[' admin ' [' a '] = 11;
$_session[' admin ' [' b '] = 22;
I hope this article is helpful to everyone's PHP programming.
PHP for two-dimensional arrays in 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 the $data=array (6 = = Array (' name ' = = ' AA ', ' price ' = = '), ' + ' array (' name ' = = ' BB ', ' price ') = 102));
Session_register ("Data");
echo "Go b</a>";
?>
b.php
Session_Start ();
Print_r ($HTTP _session_vars[' data ');
?>
The code is very simple to write. haha.
"Teach, PHP," How is this $_session two-dimensional array understood?
$_session[' cart ' [$ISBN] is a two-dimensional array, such as:
The cart represents a person's shopping cart,
$ISBN representative is an item.
Now I go shopping, this cart represents me.
I bought a computer, a TV, $ISBN on behalf of the computer or television, specifically the computer or television, it depends on the $_post["save" the value passed.
If it comes to computers then $_session[' cart ' [$isbn]= "Computer".
http://www.bkjia.com/PHPjc/907284.html www.bkjia.com true http://www.bkjia.com/PHPjc/907284.html techarticle PHP uses the session two-dimensional array instance, session two-dimensional array example This article describes the use of the session of PHP using the two-dimensional array. Share to everyone for your reference. Specific as follows: most common ...