Details about creating a php array

Source: Internet
Author: User
Details about creating a php array
$name1 = "aaaaa";$name2 = 'bbbbb';$data = array(         "userid" => $name1,         "department" => [1, 2],         "position" => $name2,         "mobile" => "15913215421",      );


I want to know what the corresponding positions of the userid and position in the $ data array are ("aaaaa", "aaaaa", "bbbbb", or "bbbbb ')
What is output when $ data ['userid'] and $ data ['position'] are output ("aaaaa", "aaaaa", "bbbbb", or "bbbbb ")? ')


Reply to discussion (solution)

You var_export ($ data );
And echo $ data ['userid'];
You can see

$ Name1 = "aaaaa ";
$ Name2 = 'bbbbbb ';
Quotation marks are only delimiters and do not belong to string content.
The difference between double quotes and single quotes is that the double quotes will explain the variables, but the single quotes will not.

In your example, single quotes and double quotes are the same.

$ Data ['userid'] is a string aaaaa
$ Data ['position'] is a string bbbbb


You var_export ($ data );
And echo $ data ['userid'];
You can see



Why did I encounter this problem:
Array ('userid' => '\ 'abc123 '\',..............)
When a string is passed in, the quotation marks are also forcibly inserted, so two escape characters "\" are generated "\"

$ Name1 = "aaaaa ";
$ Name2 = 'bbbbbb ';
Quotation marks are only delimiters and do not belong to string content.
The difference between double quotes and single quotes is that the double quotes will explain the variables, but the single quotes will not.

In your example, single quotes and double quotes are the same.

$ Data ['userid'] is a string aaaaa
$ Data ['position'] is a string bbbbb



You var_export ($ data );
And echo $ data ['userid'];
You can see



Why did I encounter this problem: when printing the entire array
Array ('userid' => '\ 'abc123 '\',..............)
When a string is passed in, the quotation marks are also forcibly inserted, so two escape characters "\" are generated "\"

You var_export ($ data );
And echo $ data ['userid'];
You can see


You var_export ($ data );
And echo $ data ['userid'];
You can see



Why did I encounter this problem: when I print the entire array (that was wrong just now)
Array ('userid' => '\ 'abc123 \'',..............)
When a string is passed in, the quotation marks are also forcibly inserted, so two escape characters "\" are generated "\"

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.