In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article Xiaobian for you to introduce in detail "php how to convert two-dimensional array to three-dimensional array", the content is detailed, the steps are clear, and the details are handled properly. I hope this "php how to transfer two-dimensional array to three-dimensional array" article can help you solve your doubts.
In php, you can use the array_chunk () function to convert a two-dimensional array into a three-dimensional array, which can split an array into multiple array blocks, only need to set the length of each new array block (number of elements) through the second parameter; syntax "array_chunk (two-dimensional array, integer value)".
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the array_chunk () function to convert a two-dimensional array into a three-dimensional array.
The array_chunk () function splits an array into new array blocks.
By using this function, the array of each layer of the two-dimensional array can be divided (fractal dimension), and then converted into a three-dimensional array.
For example, there is a two-dimensional array:
$arr= array (array ("Zhang San", 25, "male"), array ("Li Si", 21, "male"), array ("Nana", 22, "female"), array ("Zhang San", 25, "male"), array ("Li Si", 21, "male"), array ("Nana", 22, "female"); echo "original 2D array:"; var_dump ($arr)
Convert a two-dimensional array to a three-dimensional array
Var_dump (array_chunk ($arr,1))
Var_dump (array_chunk ($arr,2))
Var_dump (array_chunk ($arr,3))
It can be seen that the number of elements in the third layer of the three-dimensional array varies with the value of the third parameter.
Description:
The array_chunk () function splits an array into multiple array blocks with the following syntax:
Array array_chunk (array $arr, int $size [, bool $preserve_keys = false])
Parameter description:
Arr represents the array to be split
Size represents the number of elements of the split subarray
Preserve_keys indicates whether to keep the original key name in the arr array, which defaults to false, that is, it is not retained, and each subarray after split will use a new numeric index starting at 0; if set to true, the original key name in arr will be retained.
Array_chunk () splits the arr array into multiple subarrays, and the number of elements in each subarray is determined by size. The number of elements in the last subarray may be less than size.
Return value: returns a multi-dimensional array of split subarrays.
After reading this, the article "how php converts two-dimensional arrays to three-dimensional arrays" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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.
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.