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 "\"