2013-11-28 94 views
0
echo $existing_data; 

echo $current_data; 

array_merge($existing_data->original, $current_data->original); 
array_merge($existing_data->large, $current_data->large); 
array_merge($existing_data->small, $current_data->small); 

echo $existing_data; 

的輸出是:無法合併2個陣列

"existing": { 
    "original": [], 
    "small": [], 
    "large": [], 
    "preview": { 
     "name": "", 
     "path": "", 
     "reference": "" 
    } 
} 

"current": { 
    "original": [ 
     { 
     "name": "TQT_82560100_1385618474_9480", 
     "created_timestamp": "2013-11-28 06:01:14", 
     } 
    ], 
    "small": [ 
     { 
     "name": "TQT_82560100_1385618474_9480_small", 
     "created_timestamp": "2013-11-28 06:01:15", 
     }a 
    ], 
    "large": [ 
     { 
     "name": "TQT_82560100_1385618474_9480_large", 
     "created_timestamp": "2013-11-28 06:01:15", 
     } 
    ], 
    "preview": { 
     "name": "TQT_82560100_1385618474_9480_prev", 
     "path": "images/", 
     "reference": 0, 
     "width": 137, 
     "height": 137 
    } 
} 

"existing": { 
    "original": [], 
    "small": [], 
    "large": [], 
    "preview": { 
     "name": "", 
     "path": "", 
     "reference": "" 
    } 
} 

我試圖array_merge_recursive()太。但結果相同。

回答

1

你必須保存的陣列的結果合併PHP文檔的

$result = array_merge($existing_data->original, $current_data->original); 

例如

<?php 
    $array1 = array("color" => "red", 2, 4); 
    $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4); 
    $result = array_merge($array1, $array2); 
    print_r($result); 
?> 

陣列( [顏色] =>綠 [0] => 2 [1] => 4 [2] => a [3] => b [形狀] =>梯形 [4] => 4)

1

嘗試做這樣這個 -

$array1 = $existing_data->original + $current_data->original; 
$array2 = $existing_data->large + $current_data->large; 
$array3 = $existing_data->small + $current_data->small;