Home>Article>Backend Development> The difference between php associative array and index array

The difference between php associative array and index array

(*-*)浩
(*-*)浩 Original
2019-10-09 11:14:17 4187browse

In PHP, an array is a collection of a series of data, forming an operable whole. Each data is an element, and the element contains a key name and a key value.

The difference between php associative array and index array

The difference between index array and associative array is distinguished by key name

1. Index array(Recommended learning:PHP video tutorial)



'; echo '数组 $arr 中的,键名为2的键值为:'.$arr[2]; ?>

The results show:

The difference between php associative array and index array

2. Associative array

 '苹果','Banana' => '香蕉','Orange' => '橘子','Plum' => '李子','Strawberry' => '草莓'); print_r($arr1); ?>

The result shows:

The difference between php associative array and index array

Arrays with numbers as key names are generally called index arrays and associative arrays The key values are strings and are artificially specified.

The above is the detailed content of The difference between php associative array and index array. 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