Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Whether the key name of the array in php can be repeated.

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about whether the key names of the arrays in php can be repeated. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

The key name of the php array cannot be duplicated. In php, the key of the array is unique and will not repeat. Even if two identical key names are declared, the key name of the latter declaration will overwrite the previous key name; using this feature, you can use array_flip () to reverse the key name and key value of the array twice to achieve the array deduplication effect.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The key name of the php array cannot be duplicated.

In php, the key name (key) of the array is unique and does not repeat.

Example: there is such an empty array

$arr = array (); / / define an empty array var_dump ($arr); / / output array

Declare key-value pairs

/ / define key value pair element $arr ["id"] = 1 * * name] = "Li Hua"; $arr ["age"] = 20 * dump ($arr); / / output array

Declare duplicate key names and assign values

/ / declare duplicate key names and assign a value of $arr ["id"] = 10 positionarr ["age"] = 23 transfixion dump ($arr); / / output array

You can see that even if two identical key names are declared, the key name of the latter declaration will overwrite the previous key name.

Extended knowledge: taking advantage of the non-repeatable key name of php array, the repeated values of the array can be removed.

Just use the array_flip ($array) function to reverse the key name and key value of the array twice:

First swap the key name and key value to remove the duplicate value

And then switch the key name and key value back.

These are all the contents of the article "whether the key names of arrays in php can be repeated". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report