PHP array key values use single and double quotes and unsigned differences

Source: Internet
Author: User

PHP array key values use single and double quotes and unsigned differences

Method/Step
  1. 1

    The first: $array [' key '] This single quote key value pattern can be parsed directly into an array that is $array

    The second type: $array ["key"] this double-quote key-value pattern, the first execution is "key", to determine whether there is a defined PHP variable exists, parsing the array is $array

    Third: $array [key] This is a no single double quote key value mode, which first parses the presence of a constant that has a key key value definition, that is, using define (' key ', ' Val '), and then parsing the array as $array

  2. 2

    Other conditions: For example $array["$a"] and $array[$a] differences

    1. $array ["$a"], $array [$a] in this case, the value of the array is parsed by the array subscript of the string type

    2. $array ["$a"], $array [$a] This situation has no meaning if the index type is an array

    3. $array ["$a"], $array [$a] This situation can not care about single double quotes, stating that $ A is a variable, that is $array["$a"]=== $array [$a]

  3. 3

    Detailed Examples:

    <?php

    Define (' Chang ', ' array1 ');

    $chang = ' $array 2 ';

    $bian = ' array1 ';

    $array = Array (

    ' Array1 ' = ' array1 ',

    ' $array 2 ' = ' $array 2 ',

    ' $array 3 ' = ' $array 3 ',

    );

    echo $array [' array1 ']. ' <br/> ';

    echo $array ["$bian"], ' <br/> ';

    Echo $array [Chang], ' <br/> ';

    echo $array [$chang];

PHP array key values use single and double quotes and unsigned differences

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.