array_merge_recursive use

Role : Recursive merge array

Scene : In normal development, we may encounter data is acquired multiple dimensions of data, but we only need one of them.

code show as below:

PROJECT_ID $ = 'PROJECT_ID' ;
 $ of arr1 = [
     'PROJECT_ID' => [ 'name' => 'name 1', 'address' => ' Address 1'],
    'Project_id2' => [ 'name' => 'name 2', 'address' => 'Address 2'],
];

arr2 is $ = [
     'PROJECT_ID' => [ 'room_num' => 'Room 1', 'room_type_num' => ' Number of units 1'],
    'Project_id2' => [ 'room_num' => 'Room 2', 'room_type_num' => 'Number of units 2',],
];

ARR3 $ = [
     'PROJECT_ID' => [ 'is_new' => 'whether a new store 1'],
    'Project_id2' => [ 'is_new' => 'whether the store 2'],
];

// Get the value of the project id is project_id data 
$ project_data = array_merge_recursive ( $ of arr1 , $ arr2 is , $ ARR3 ) [ $ project_id ];

 

Structure array_merge_recursive ($ arr1, $ arr2, $ arr3) are:
Array
(
   [project_id] => Array
       (
           [name] => Title 1
           [address] => Address 1
           [room_num] => Number of rooms 1
           [room_type_num] => Unit Number 1
           [is_new] => whether a store
       )
   [project_id2] => Array
       (
           [name] => name 2
           [address] => Address 2
           [room_num] => Room 2
           [room_type_num] => Unit Number 2
           [is_new] => whether the store 2
       )
)

 

 It can be seen is the dimension "project_id" consolidated data, so that we can easily get the data of a certain dimension

Guess you like

Origin www.cnblogs.com/echojson/p/12071901.html