Array conversion merged this post was finally edited by u012984377 from 2014-08-22:09:59 Array & nbsp; (& nbsp; [0] & nbsp; & gt; & nbsp; Array & nbsp; (& nbsp; [id] & nbsp; & gt; & nbsp; 9 & nbsp; [ti] & nbsp; & gt; & nbsp; array conversion and merging
This post was last edited by u012984377 at 15:09:59
Array ([0] => Array ([id] => 9 [ti] => I) [1] => Array ([id] => 10 [ti] =>) [2] => Array ([id] => 11 [ti] => Medium) [3] => Array ([id] => 11 [ti] => country ))
This is converted to a one-dimensional array ID as the KEY. I will convert it, but what should I do if the same is met?
If a one-dimensional array is obtained, the obtained one-dimensional array is merged with the following one. if the KEY is equal, the value is replaced;
Array ([7] => love [8] => I [9] => 11 [10] => 33333 [11] => 中[ [12] => Hua)
Currently, you have two questions about the exercise array. After a day, I still failed... -_-
------ Solution --------------------
$ A = Array (
Array ('id' => 9, 'ti' => 'I '),
Array ('id' => 10, 'ti' => 'our '),
Array ('id' => 11, 'ti' => '中 '),
Array ('id' => 11, 'ti' => 'Country ')
);
$ Res = array ();
Foreach ($ a as $ r ){
If (isset ($ res [$ r ['id']) $ res [$ r ['id']. = $ r ['ti'];
Else $ res [$ r ['id'] = $ r ['ti'];
}
Print_r ($ res );
Array
(
[9] => me
[10] =>
[11] => China
)