Home  >  Article  >  Backend Development  >  Does php array only support numeric subscripts?

Does php array only support numeric subscripts?

青灯夜游
青灯夜游Original
2021-11-16 17:42:133123browse

No, the subscript (index value) of the PHP array can be a string or a number. The array whose subscript is a string is an associative array, which is an array with a special indexing method; the array whose subscript is a number is an index array, and its subscript value must be an integer, starting from 0 and so on.

Does php array only support numeric subscripts?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, under the array The index (index value) can be a string or a number.

  • The array whose subscript is a string is an associative array

  • The array whose subscript is a number is an index array

Index array

Index array stores an organized sequence of single or multiple values, each of which can be identified by using an unsigned integer value for a visit. The keys of the index array are integers and start from 0 and so on.

Does php array only support numeric subscripts?

Associative array

"Associative array" is an array with a special indexing method. Index it using a string or other type of value (except NULL).

In fact, the difference between associative arrays and index arrays is only in the key values. The key values ​​of associative arrays are strings, and they are artificial regulations.

<?php
header("Content-type:text/html;charset=utf-8");
//创建一个关联数组,关联数组的键“orange”,值是“橘子”  
$age=array("Peter"=>"35","Ben"=>"43","Joe"=>"42");
var_dump($age);
?>

Does php array only support numeric subscripts?

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Does php array only support numeric subscripts?. 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