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

How to convert array value to key by php

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

Share

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

In this article, Xiaobian introduces in detail "how php converts array value to key" with detailed content, clear steps and proper handling of details. I hope that this article "how php converts array value to key" can help you solve your doubts.

Three methods: 1, use the "array_flip ($arr)" statement; 2, use the "array_combine ($arr,array_keys ($arr))" statement; 3, use the "foreach ($arr1 as $k = > $v) {$arr2 [$v] = $k;}" statement.

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

Php converts the array value to key, that is, converting the keys and values in the array to each other. Here are three methods:

Method 1: use the array_flip () function

The array_flip () function can exchange keys and values in an array

Method 2: use the array_keys () + array_combine () function

Realize the idea:

Use array_keys () to get the key names in the array and return the array of key names

Use array_combine () to merge the original array as the key name and the key name array as the key value to form a new array

Method 3: use foreach loop and an empty array

Read this, the "php how to convert array value to key" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow 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