也許它看起來很簡單,但它讓我瘋狂。 這裏是我的數組:陣列合併失敗
$result =
Array
(
[0] => Array
(
[0] => 4
[1] => 4
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
[9] => 4
[10] => 40
)
[1] => Array
(
[0] => 5
[1] => 4
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
[9] => 4
[10] => 41
)
[2] => Array
(
[0] => 5
[1] => 5
[2] => 5
[3] => 5
[4] => 5
[5] => 5
[6] => 5
[7] => 5
[8] => 5
[9] => 5
[10] => 50
)
)
這就是我想要的東西轉化爲:
$result =
Array
(
[0] => 4
[1] => 4
[2] => 4
[3] => 4
[4] => 4
[5] => 4
[6] => 4
[7] => 4
[8] => 4
[9] => 4
[10] => 40
[11] => 5
[12] => 4
[13] => 4
[14] => 4
[15] => 4
[16] => 4
[17] => 4
[18] => 4
[19] => 4
[20] => 4
[21] => 41
[22] => 5
[23] => 5
[24] => 5
[25] => 5
[26] => 5
[27] => 5
[28] => 5
[29] => 5
[30] => 5
[31] => 5
[32] => 50
)
這是代碼:
<?php
$result = array();
?>
@foreach ($detail_ratings as $detail_rating)
<?php $result[] = json_decode($detail_rating); ?>
@endforeach
<?php
$result = array_merge($result[0],$result[1],$result[2]);
?>
{{print_r($result)}}
array_merge後
我如何讓它自動不使用此代碼手動:
$result = array_merge($result[0],$result[1],$result[2]);
這是我已經做了:
foreach ($result as $key => $value) {
$values[] = array_merge($value,$result[$key]);
}
感謝您的回答noufalcep! – 2014-10-08 06:07:57