无法从cakephp2中的find('all')合并嵌套数组数据

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?

You can create the temporary $data array and merge everything and then assign to the $fixed_arrays list

<?php

    $res = $this->find( 'all', $cond); // All the data are fetched from this $res
    $count = count($res);
    for($i=0;$i<$count;$i++){
       $result[] =  $res[$i] ;
       $data =array(); //temporary array

        $data['MyData'] = $result[$i]['MyData'];
        if (!empty($result[$i]['c']) && isset($result[$i]['c']['my_test'])) {
            $corrupt_c_array = $result[$i]['c'];
            $data['MyData']['my_test'] = $result[$i]['c']['my_test'];            
        }
        if(!empty($result[$i]['a']) && isset($result[$i]['a']['my_date'])) {
            $corrupt_a_array = $result[$i]['a'];
            $data['MyData']['my_date'] = $result[$i]['a']['my_date']; 
        }
        $fixed_arrays[] = $data; 

    }
    $result['data'] = $fixed_arrays; 

If you use the condition then you can not get the all values if it will blank so use like this :

   <?php
$res = $this->find('all', $cond); // All the data are fetched from this $res
$count = count($res);
for ($i = 0; $i < $count; $i++) {
    $result[] = $res[$i];
    $data = array(); //temporary array

    $data[$i]['MyData'] = $result[$i]['MyData'];

    $data[$i]['MyData']['my_test'] = $result[$i]['c']['my_test'];


    $data[$i]['MyData']['my_date'] = $result[$i]['a']['my_date'];
}

$result['data'] = $data;

Just Print the $data or $result to get array like you want.

$res = $this->find ( 'all', $cond );
foreach ( $res as &$result ) {
    $result ['MyData'] ['my_test'] = $result ['c'] ['my_test'];
    $result ['MyData'] ['my_date'] = $result ['a'] ['my_date'];
    unset ( $result ['a'] );
    unset ( $result ['c'] );
}
echo "<pre>";
print_r ( $res );
exit ();