I try to merge the data's in the arrays 'c' and 'a' inside MyData
with the following code, but the outcome was still corrupted.
Are there something wrong with my code ? Or am I simple making a mistake with how I merge the arrays ? I'm doing all sorts of stuff to solve the problem but cannot find any solution that works. Some examples or tips will be great!
Want to merge [my_test]
and [my_date]
inside [MyData]
.
Array
(
[0] => Array
(
[MyData] => Array
(
[id] => 79
[my_birth_day] => 1990-06-20
[my_address] => 400
[my_age] => 26
[my_name] => Joy
[my_id] => 1
[created] => 2017-06-19 15:39:44
)
[c] => Array
(
[my_test] => math
)
[a] => Array
(
[my_date] => 2017-08-13
)
).....Loops
[1] => Array
(
I would want the result to be like
Array
(
[0] => Array
(
[MyData] => Array
(
[id] => 79
[my_birth_day] => 1990-06-20
[my_address] => 400
[my_age] => 26
[my_name] => Joy
[my_id] => 1
[created] => 2017-06-19 15:39:44
[my_test] => math
[my_date] => 2017-08-13
I made a logic to merge the arrays and display it as the above code , but wasn't able to merge
$res = $this->find( 'all', $cond); // All the data are fetchd from this $res
$count = count($res);
for($i=0;$i<$count;$i++){
$result[] = $res[$i] ;
$fixed_arrays[] = $result[$i]['MyData'];
if (!empty($result[$i]['c'])) {
$corrupt_c_array = $result[$i]['c'];
$fixed_arrays = array_merge($fixed_arrays,$corrupt_c_array);
}
if(!empty($result[$i]['a'])) {
$corrupt_a_array = $result[$i]['a'];
$fixed_arrays = array_merge($fixed_arrays, $corrupt_a_array);
}
}
$result['data'] = $fixed_arrays; // This $result['data'] should show the expected result.
[Update] Heard about a function called set::combine for cakephp2, Is there a way to use set::combine since it's cakephp2?