PHP framework-There are multiple sibling arrays in the PHP array, which you want to merge into an array

Source: Internet
Author: User
Tags php framework
The result of printing is multiple sibling array, first see, want to merge into a large array, easy to operate

Array ([0] = = Array ([title] + Yue Moving line) [1] = = Array ([title]            = a tour is good) [2] = = Array ([title] + Tour Companion) [3] = = Array (        [title] [4] = = Array ([title] + Master explanation-Dashi solution) [5] = = Array    ([title] = Take Me to fly) [6] = = Array ([title] = Musimin Homestay) [7] = = Array ([title] = Play Companion pet Travel) [8] = = Array ([title] = + Japan Deep Study Tour network) [9] = = Array ([        (Title] = Roaming live)) Array ([0] = = Array ([title] = Trip) [1] = = Array    ([title] = Fast Travel) [2] = = Array ([title] + Independence Day travel) [3] = = Array ([title] = = BInk      Ky Chuang Si Han Woo) [4] = = Array (      [title] + squid travel) [5] = = Array ([title] = with Kee Yoki) [6] = = Array    ([title] = Met Rong) [7] = = Array ([title] + 23place) [8] = = Array ([title] = + Tour Will) [9] = = Array ([title] = Ouch travel))

Reply content:

The result of printing is multiple sibling array, first see, want to merge into a large array, easy to operate

Array ([0] = = Array ([title] + Yue Moving line) [1] = = Array ([title]            = a tour is good) [2] = = Array ([title] + Tour Companion) [3] = = Array (        [title] [4] = = Array ([title] + Master explanation-Dashi solution) [5] = = Array    ([title] = Take Me to fly) [6] = = Array ([title] = Musimin Homestay) [7] = = Array ([title] = Play Companion pet Travel) [8] = = Array ([title] = + Japan Deep Study Tour network) [9] = = Array ([        (Title] = Roaming live)) Array ([0] = = Array ([title] = Trip) [1] = = Array    ([title] = Fast Travel) [2] = = Array ([title] + Independence Day travel) [3] = = Array ([title] = = BInk      Ky Chuang Si Han Woo) [4] = = Array (      [title] + squid travel) [5] = = Array ([title] = with Kee Yoki) [6] = = Array    ([title] = Met Rong) [7] = = Array ([title] + 23place) [8] = = Array ([title] = + Tour Will) [9] = = Array ([title] = Ouch travel))

The array_column,php version requires 5.5 +

$arr1 = Array(    Array        (            'title' => '悦动行出游',        ),     Array        (            'title' => 'A游不错',        ));  $arr2= Array(    Array        (            'title' => '悠比旅行',        ),     Array        (            'title' => '快快旅行',        ));        var_dump(array_merge(array_column($arr1,'title'),array_column($arr2,'title')));    array(4) {  [0]=>  string(15) "悦动行出游"  [1]=>  string(10) "A游不错"  [2]=>  string(12) "悠比旅行"  [3]=>  string(12) "快快旅行"}            

Using the Array_merge method

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

Suppose you have two-dimensional arrays above that are $ARR1 and $ARR2, respectively.
First Use the function Array_column () that gets the value of the two-dimensional array column,
The value of the ' title ' field in two arrays is taken to two anonymous index arrays, respectively.
Array_column ($arr 1, ' title ');
Then use the Array_merge () array merge function to combine two numbers and:
$new _arr = Array_merge (Array_column ($arr 1, ' title '), Array_column ($arr 2, ' title '));

  • Related Article

    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.