PHP uses session two-dimensional array instance, session two-dimensional array instance _php tutorial

Source: Internet
Author: User
Tags array example php programming

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

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