Not found in the explicit PHP definition of associative array/index array parsing, according to Phpdocument and Baidu some of the data and the actual code test, the associative array/index data to define the resolution. This problem is mainly encountered when the mobile phone-side iOS app offers APIs, and using an associative array to JSON can better convert the array with OC resolution.
Associative array: There is no explicit index key, starting with 0 as the index key by default.
$temp _arr = Array (
' already bought elsewhere ',
' goods do not meet demand ',
' The price is too high ',
' don't want to buy ',
' sellers have no transaction history ',
' Other reasons ',
);
$temp _arr[0] = ' already bought elsewhere ';
$temp _arr[1] = ' goods do not meet demand ';
Press Print_f () to print the array:
Array ([0] = = has been bought elsewhere [1] and the product does not meet demand [2] = = Price is too high [3]/= don't want to buy [4]/= Seller no transaction record [5] = other reason)
Convert to JSON output:
["\u5df2\u7ecf\u5728\u522b\u5904\u4e70\u5230", "\u5546\u54c1\u4e0d\u7b26\u5408\u9700\u6c42", "\u4ef7\ U683c\u592a\u9ad8 "," \u4e0d\u60f3\u4e70\u4e86 "," \u5356\u5bb6\u6ca1\u6709\u4ea4\u6613\u8bb0\u5f55 "," \u5176\u4ed6 \u539f\u56e0 "]
Indexed arrays: There are explicit index keys that form key-value pairs of relationships.
$temp _arr = Array (
' 1 ' = ' has been bought elsewhere ',
' 2 ' = ' goods do not meet demand ',
' 3 ' = ' Price is too high ',
' 4 ' = ' Don't want to buy ',
' 5 ' = ' sellers have no transaction history ',
' 6 ' = ' other reason ',
);
Press Print_f () to print the array:
Array ([1] = = has been bought elsewhere [2] and the product does not meet demand [3] = = Price is too high [4]/= don't want to buy [5]/= Seller no transaction record [6] = other reason)
Convert to JSON output:
{"1": "\u5df2\u7ecf\u5728\u522b\u5904\u4e70\u5230", "2": "\u5546\u54c1\u4e0d\u7b26\u5408\u9700\u6c42", "3": "\ U4ef7\u683c\u592a\u9ad8 "," 4 ":" \u4e0d\u60f3\u4e70\u4e86 "," 5 ":" \u5356\u5bb6\u6ca1\u6709\u4ea4\u6613\u8bb0\u5f55 " , "6": "\u5176\u4ed6\u539f\u56e0"}
PHP associative array and indexed array differences