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

The relationship between keys and values ​​in php arrays

angryTom
Release: 2023-02-28 10:32:01
Original
3595 people have browsed it

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" }
?>
Copy after login

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!

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