In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the "php merging array method tutorial". In the daily operation, I believe that many people have doubts on the php merging array method tutorial. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "php merging array method tutorial". Next, please follow the editor to study!
Merge method: 1, use "array 1 + array 2" statement; 2, use "array_merge (array 1, array 2)" statement; 3, use "array_merge_recursive (array 1, array 2)" statement; 4, use "array_combine (array 1, array 2)" statement.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
1. Use the plus sign "+" operator:
Directly merge the values of two arrays into one array
Output result:
Merge arrays with "+". If the keys are the same, the previous array values will overwrite the subsequent array values.
2. Use the array_merge () function
Merge the two arrays directly. If the keys of the two arrays are the same, the values of the following array overwrite the values of the previous array.
Output result:
As you can see, if the keys of the two arrays are the same, the value of the later array overrides the value of the previous array. However, for a numeric index or a numeric string index, it is reset sequentially (the first numeric index element of the first array is populated from 0)
3. Use the array_merge_recursive () function
Merge the array, encounter the same key and merge the median value of the key into a subarray
Output result:
When using the "array_merge_recursive" method, the elements of the same key are integrated into a new array, leaving the key name unchanged as a child of the merged array (the combination of $an and $b). However, for a numeric index or a numeric string index, it is reset sequentially (the first numeric index element of the first array is populated from 0). Even if the corresponding numeric index is the same, the elements of the same index will not be successfully integrated into a subarray.
4. Use the array_combine () function
The array_combine () function creates a new array by merging two arrays, one of which is the key name and the other is the key value.
Note: the number of elements in the key name array and the key value array must be the same!
Output result:
At this point, the study of "the method tutorial of merging arrays in php" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.