There are several ways we write traversal arrays, such as direct $arr[\ ' key\ ' and $arr [\ ' key\ '] and $arr [key] We can all show off the content, but where do they differ, let me introduce you.
The difference between the $arr [' key '] and the $arr ["key"] and the $arr [key]:
The above three ways are mainly through the string type array subscript is the array key to access the value of the array, if the array subscript index type is the key value of the number is not to be aware.
1, $arr [' key '] single quote mode is parsed directly to the value of $arr;
2, $arr ["key"] double quote mode will first analyze whether the "key" string contains PHP variables, and then resolves to $arr values;
3, $arr [key] without any quotation marks will first analyze whether there is a key constant definition in the local scope (that is, there is no define (' key ', ' Val ')),
If any, use the constant value represented by the local key constant as the array key value;
Otherwise, there is no key constant definition in the global scope,
If any, the constant value represented by the global key constant is used as the array key value;
Otherwise the internal conversion key is the ' key ' string scalar value and throws a E_notice exception.
Ii. differences between $arr ["$str _key"] and $arr [$str _key]
This method also accesses the value of the array through the array of string type arrays,
If the array is indexed as an index type then the number is not to be noticed.
In fact, there is no need to add double quotation marks to indicate that the $str_key variable represents a string value.
i.e. $arr["$str _key"] = = = $arr [$str _key]
The code is as follows |
Copy Code |
Define (' constant ', ' arr1 '); $constant = ' arr2 '; $variable = ' arr1 '; $arr = Array ( ' arr1 ' = ' arr1 ', ' arr2 ' = ' arr2 ', ' Arr3 ' = ' arr3 ', );
echo $arr [' arr1 '], ' ', $arr ["$variable"], ' ', $arr [constant], ' ', $arr [$constant];
?> |
http://www.bkjia.com/PHPjc/632804.html www.bkjia.com true http://www.bkjia.com/PHPjc/632804.html techarticle There are several ways we write traversal arrays, such as direct $arr[\ ' key\ ' and $arr [\ ' key\ '] and $arr [key] We can all show what we want to close, but where do they differ?