Home  >  Article  >  Backend Development  >  Can the key in a php array be a character?

Can the key in a php array be a character?

青灯夜游
青灯夜游Original
2022-06-02 16:28:252601browse

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.

Can the key in a php array be a character?

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(&#39;content-type:text/html;charset=utf-8&#39;);   
$str1="a";
$str2="abcd";
$str3="ab23";
var_dump($str1);
var_dump($str2);
var_dump($str3);
?>

Can the key in a php array be a character?

And the key name (key) of the php array can be an integer type or a string type

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$arr=array(1=>"1","a"=>"red","ab"=>"2","b12"=>"green",3=>"3");
var_dump($arr);
?>

Can the key in a php array be a character?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn