In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "php how to modify the array subscript", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "php how to modify the array subscript" bar!
Two methods: 1. Using the "array_values ($arr)" statement, you can convert an associative array into an indexed array and a string subscript into a pure numeric subscript. 2, use "array_combine (key name array, original array)" statement, the elements of one array as the subscript of another array, the number of elements of the two arrays should be the same.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Two methods of modifying Array subscript by php
1. Use the array_values () function
The array_values () function converts an associative array into an indexed array and converts a string subscript to a pure numeric subscript.
2. Use the array_combine () function
The array_combine () function can take the elements of one array as the key name (subscript) of another array.
Example 1: convert an indexed array to an associative array
Example 2: modify the subscript of an associative array
Description:
The array_combine ($keys,$values) function creates a new array by merging two arrays, where the element in the $keys array is the key name of the new array, and the element of the $values array is the key value of the new array.
It is important to note, however, that when creating an array using the array_combine () function, the number of elements in the $keys array and the $values array must be the same, so that the key name and key value correspond one to one, otherwise an error will be reported and FALSE will be returned.
And the $keys array cannot be a multi-dimensional array, otherwise an error will be reported, but the $values array can be a multi-dimensional array.
Thank you for your reading, the above is the content of "how to modify the subscript of the array by php". After the study of this article, I believe you have a deeper understanding of how to modify the subscript of the array by php, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.