Home > Article > Backend Development > Can the key in a php array be a character?
The key name (key) of the php array can be characters. In PHP, characters and strings are uniformly regarded as string data types, and the key name (key) of the array can be an integer type or a string type; therefore, the key name (key) of the array can be an integer value, a single character, or a character. Strings or characters mixed with numbers.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The key name of the php array (key ) can be a character.
In other languages, characters and strings are two different data types, but in PHP, characters and strings are uniformly regarded as string data types.
<?php header('content-type:text/html;charset=utf-8'); $str1="a"; $str2="abcd"; $str3="ab23"; var_dump($str1); var_dump($str2); var_dump($str3); ?>
And the key name (key) of the php array can be an integer type or a string type
<?php header('content-type:text/html;charset=utf-8'); $arr=array(1=>"1","a"=>"red","ab"=>"2","b12"=>"green",3=>"3"); var_dump($arr); ?>
Yes It can be seen that the key name of the array can be an integer value, a single character, a string, or a mixture of characters and numbers.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can the key in a php array be a character?. For more information, please follow other related articles on the PHP Chinese website!