Php framework-the php array contains multiple same-level arrays, and you want to merge them into an array.

Source: Internet
Author: User
The printed result is multiple arrays of the same level. for the first time, you can see that you want to merge them into a large array to facilitate the {code...} operation ...} the printed result is multiple same-level arrays. for the first time, you can see that you want to merge them into a large array to facilitate operations.

Array ([0] => Array ([title] => Yueda travel) [1] => Array ([title] => A game is good) [2] => Array ([title] => traveling companion) [3] => Array ([title] => Housing Market) [4] => Array ([title] => ---) [5] => Array ([title] => Fly With Me) [6] => Array ([title] => Mu Xi homestay) [7] => Array ([title] => traveling with a companion pet) [8] => Array ([title] => Japanese Deep Learning Network) [9] => Array ([title] => cloud game live broadcast )) array ([0] => Array ([title] => Youbi travel) [1] => Array ([title] => Fast Trip) [2] => Array ([title] => Independent Day travel) [3] => Array ([title] => BInkky chuangsihanyu) [4] => Array ([title] => squid travel) [5] => Array ([title] => note YOKI) [6] => Array ([title] => Yu Youbang) [7] => Array ([title] => 23 place) [8] => Array ([title] => Youhui) [9] => Array ([title] => ouyo travel ))

Reply content:

The printed result is multiple same-level arrays. for the first time, you can see that you want to merge them into a large array to facilitate operations.

Array ([0] => Array ([title] => Yueda travel) [1] => Array ([title] => A game is good) [2] => Array ([title] => traveling companion) [3] => Array ([title] => Housing Market) [4] => Array ([title] => ---) [5] => Array ([title] => Fly With Me) [6] => Array ([title] => Mu Xi homestay) [7] => Array ([title] => traveling with a companion pet) [8] => Array ([title] => Japanese Deep Learning Network) [9] => Array ([title] => cloud game live broadcast )) array ([0] => Array ([title] => Youbi travel) [1] => Array ([title] => Fast Trip) [2] => Array ([title] => Independent Day travel) [3] => Array ([title] => BInkky chuangsihanyu) [4] => Array ([title] => squid travel) [5] => Array ([title] => note YOKI) [6] => Array ([title] => Yu Youbang) [7] => Array ([title] => 23 place) [8] => Array ([title] => Youhui) [9] => Array ([title] => ouyo travel ))

Array_column, php version requires 5.5 +

$ Arr1 = Array ('title' => 'Happy traveling out',), Array ('title' => 'A Good Game ',)); $ arr2 = Array ('title' => 'youbi travel',), Array ('title' => 'kuaiyou ',)); var_dump (array_merge (array_column ($ arr1, 'title'), array_column ($ arr2, 'title'); array (4) {[0] => string (15) "Yueda travel" [1] => string (10) "A tour is good" [2] => string (12) "Youbi travel" [3] => string (12) ""}

Use the array_merge method

array_map(function($v){     return $v['title'];    }, $arr);

Assume that the preceding two 2D arrays are $ arr1 and $ arr2.
First, use the array_column () function to obtain the values of two-dimensional array columns (),
The values of the 'title' field in the two arrays are obtained in two anonymous index arrays.
Array_column ($ arr1, 'title ');
Then use the array_merge () array merging function to merge the two arrays:
$ New_arr = array_merge (array_column ($ arr1, 'title'), array_column ($ arr2, 'title '));

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.