Home > Backend Development > PHP Problem > What are the two types of php arrays based on index?

What are the two types of php arrays based on index?

silencement
Release: 2023-02-24 21:40:01
Original
3864 people have browsed it

What are the two types of php arrays based on index?

Index array

Arrays with numbers as key names are generally called index arrays. An array whose keys are represented by strings is an associative array that will be introduced below. The keys of the index array are integers and start from 0 and so on.

Index array initialization example:

<pre name="code" class="php"><?php  
//创建一个索引数组,索引数组的键是“0”,值是“苹果”  
$fruit=array("苹果","香蕉");  
print_r($fruit);  
?>
Copy after login

Running result

Array
(
    [0] => 苹果
    [1] => 香蕉
)
Copy after login

Associative array

In fact, associative array The difference from the index array is only in the key value. The key value of the associative array is a string, and it is an artificial regulation, for example:

<?php  
//创建一个关联数组,关联数组的键“orange”,值是“橘子”  
$fruit=array(&#39;orange&#39;=>&#39;橘子&#39;);  
echo $fruit[&#39;orange&#39;];  
?>
Copy after login

The above is the detailed content of What are the two types of php arrays based on index?. 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