In PHP, if the array key name is an integer numeric type, you do not need to add quotes; and if the array key name is a string type, you need to add quotes. If a key name in an array is not a number, then the array is an associative array. The key name of the associative array can be any integer or string; and if the key name is a string, add a Delimitation modifier, that is, add single quotes "''" or double quotes """".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
In php, the array key name Whether to add quotes depends on the data type of the key name.
If the array key name is an integer numeric type, no quotation marks are needed;
<?php header("Content-type:text/html;charset=utf-8"); $arr = array(1=>"a",2=>"b",3=>"c",4=>"d",5=>"e",); var_dump($arr); ?>
If the array key name is a string type, you need to add quotes
<?php header("Content-type:text/html;charset=utf-8"); $arr=array(1=>"1","a"=>"",2=>"2","b23"=>0,"12r3"=>"blue"); var_dump($arr); ?>
Instructions:
In a PHP array, no matter what type of key name there will be a value corresponding to it, that is, a key/value pair. According to the different data types of the array key names, we can divide the PHP array into There are two types:
Using numbers as key names is called an indexed array (Indexed Array);
Using strings or strings, An array in which numbers are mixed as keys is called an Associative Array.
The subscript (key name) of an associative array is composed of a mixture of numeric values and strings. If a key name in an array is not a number, then the array is an associative array.
The key name of the associative array can be any integer or string. If the key name is a string, add a delimiting modifier to the key name - single quote ' ' or double quote " ".
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Whether the php array key name should be quoted or not. For more information, please follow other related articles on the PHP Chinese website!