Details about creating a PHP array

Source: Internet
Author: User
$name 1 = "AAAAA"; $name 2 = ' bbbbb '; $data = Array (         "userid" = = $name 1,         "department" = [1, 2],         "position" = = $name 2,         "mobile" = "15913215421",      );


Want to know what the UserID and position correspond to in the $data array (is "aaaaa" or ' aaaaa ' is "bbbbb" or ' bbbbb ')
What if output $data[' userid ' and $data[' position '] are output separately ("AAAAA" or "AAAAA" is "bbbbb" or ' bbbbb ')


Reply to discussion (solution)

You Var_export ($data);
and Echo $data [' userid '];
You can see

$name 1 = "AAAAA";
$name 2 = ' bbbbb ';
Quotation marks are just delimiters and do not belong to string contents
The difference between a double-cited or a single-citation is that the double-citation interprets the variable inside, and the single-lead does not.

And your example, using single quotes and double quotes is 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 I ran into this problem:
Array (' userid ' = ' \ ' ABC123 ' \ ',..............)
One of the strings passed in and forced the quotes into the box, so we brought two escape characters, "\"

$name 1 = "AAAAA";
$name 2 = ' bbbbb ';
Quotation marks are just delimiters and do not belong to string contents
The difference between a double-cited or a single-citation is that the double-citation interprets the variable inside, and the single-lead does not.

And your example, using single quotes and double quotes is 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 I ran into this problem: When printing the entire array
Array (' userid ' = ' \ ' ABC123 ' \ ',..............)
One of the strings passed in and forced the quotes into the box, so we brought two escape characters, "\"

You Var_export ($data);
and Echo $data [' userid '];
You can see


You Var_export ($data);
and Echo $data [' userid '];
You can see



Why I ran into this problem: when I printed the entire array (the one that was wrong just now)
Array (' userid ' = ' \ ' abc123\ ',..............)
One of the strings passed in and forced the quotes into the box, so we brought two escape characters, "\"
  • 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.