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

Does php array only support numeric subscripts?

青灯夜游
Release: 2023-03-13 20:50:02
Original
3219 people have browsed it

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template