Merge thinkphp arrays

Source: Internet
Author: User
In the case of infinite classification, according to the id of the level-1 directory, it is necessary to read all the level-3 directories in the level-1 directory, and then read them in a foreach loop, there are five arrays, how can we merge them into an array? we used the array_merge () function, but the result is still five arrays, which are not successfully merged. {... Problems encountered during unlimited classification
Read all the level-3 directories in the level-1 directory based on the id of the level-1 Directory.
The foreach loop reads 5 arrays. how can we combine them into an array?
I used the array_merge () function, but the result is still five arrays. the merging is not successful.

Array (size = 3) 0 => array (size = 2) 'type _ name' => string 'oil-2 type' (length = 11) 'type _ id' => string '8' (length = 1) 1 => array (size = 2) 'type _ name' => string 'oil-3 type' (length = 11) 'type _ id' => string '9' (length = 1) 2 => array (size = 2) 'type _ name' => string 'oil-4 type' (length = 11) 'type _ id' => string '10' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips '(length = 12) 'type _ id' => string '20' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips 1' (length = 13) 'type _ id' => string '21' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips 1212 '(length = 16) 'type _ id' => string '22' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'oil pump 22 type' (length = 14) 'type _ id' => string '19' (length = 2)

Reply content:

Problems encountered during unlimited classification
Read all the level-3 directories in the level-1 directory based on the id of the level-1 Directory.
The foreach loop reads 5 arrays. how can we combine them into an array?
I used the array_merge () function, but the result is still five arrays. the merging is not successful.

Array (size = 3) 0 => array (size = 2) 'type _ name' => string 'oil-2 type' (length = 11) 'type _ id' => string '8' (length = 1) 1 => array (size = 2) 'type _ name' => string 'oil-3 type' (length = 11) 'type _ id' => string '9' (length = 1) 2 => array (size = 2) 'type _ name' => string 'oil-4 type' (length = 11) 'type _ id' => string '10' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips '(length = 12) 'type _ id' => string '20' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips 1' (length = 13) 'type _ id' => string '21' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'Phillips 1212 '(length = 16) 'type _ id' => string '22' (length = 2) array (size = 1) 0 => array (size = 2) 'type _ name' => string 'oil pump 22 type' (length = 14) 'type _ id' => string '19' (length = 2)

Usearray_merge()Function to merge multiple one-dimensional arrays.

I just read it wrong. these are all two-dimensional arrays. Then we can only assemble the array after foreach.

How many times have I checked the database? In fact, it can be detected once and then processed.
I don't know how to merge the data with the original one? Or is the structure you want not described as this?


  'Oil-2', 'type _ id' => '8'], ['type _ name' => 'oil-2 ', 'type _ id' => '2'], ['type _ name' => 'oil-2 ', 'type _ id' => '3'],]; $ array2 = [['type _ name' => 'oil-2 ', 'type _ id' => '6'], ['type _ name' => 'oil-2 type ', 'type _ id' => '22'],]; $ arrays = array_merge ($ array1, $ array2); var_dump ($ arrays );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.