Home  >  Article  >  Backend Development  >  The relationship between keys and values ​​in php arrays

The relationship between keys and values ​​in php arrays

angryTom
angryTomOriginal
2019-11-02 10:28:503476browse

The relationship between keys and values ​​in php arrays

The relationship between keys and values ​​in php arrays

● Keys in php arrays can be repeated, but repeated keys The value will be overwritten by the later one.

● Values ​​with different keys in the php array can be repeated.

● Elements in the php array can have keys or no keys.

<?php
// 键可以重复,不会报错,但重复的键的值会被后面的覆盖
$arr = array(&#39;a&#39; => &#39;a&#39;, &#39;a&#39; => &#39;b&#39;);
var_dump($arr);
// 结果
// array(1) { ["a"]=> string(1) "b" }

// 数组元素可以有键,也可以没有键
$arr1 = array(&#39;a&#39;, &#39;b&#39; => &#39;b&#39;);
var_dump($arr1);
// 结果
// array(2) { [0]=> string(1) "a" ["b"]=> string(1) "b" }
?>

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of The relationship between keys and values ​​in php arrays. 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