私は2つの配列を持っています。配列1と配列2です。 どちらの配列にも2つのレコードがあります。複数の配列をPHPでマージする
今、私は1つのアレイ内のアレイの両方をマージする必要があります。..
私はU_DATAから2つのフィールドの下に取得しています私の二番目の配列で。
[totalcharge] => 15
[RoadTotal] => 15
今私は、最初の配列で、このフィールドをマージする必要があります。..
私を助けてください、私は複数のアレイをマージする必要があります。以下は問題です:
私はこのような何かを試してみました...しかし、私は私の予想出力を達成することはできません。..
$abc = array_merge($content,$modecost);
**Array 1**
Array
(
[0] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 2046
)
[dest_city] => Array
(
[dest_pcode] => 4361
)
)
[1] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 3170
)
[dest_city] => Array
(
[dest_pcode] => 4670
)
)
)
**Array 2**
Array
(
[0] => Array
(
[u_data] => Array
(
[totalcharge] => 15
[RoadTotal] => 15
)
)
[1] => Array
(
[u_data] => Array
(
[totalcharge] => 15
[RoadTotal] => 15
)
)
)
最終的に私はそれがこの
Array
(
[0] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
[totalcharge] => 15
[RoadTotal] => 15
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 2046
)
[dest_city] => Array
(
[dest_pcode] => 4361
)
)
[1] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
[totalcharge] => 15
[RoadTotal] => 15
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 3170
)
[dest_city] => Array
(
[dest_pcode] => 4670
)
)
)
ようになりたいです私は、コードが、私が望むように異なる結果を得るの下にしようとarray_merge_recursive
の出力...
$array3 = array_merge_recursive($content, $modecost);
echo"<pre>"; print_r($array3);
exit();
私はarray_merge_recursiveが働くだろうと思ったが、そのように動作していないよう
Array
(
[0] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 2046
)
[dest_city] => Array
(
[dest_pcode] => 4361
)
)
[1] => Array
(
[u_data] => Array
(
[Mode] => Rail
[TotalCost] => 150
)
[0] => Array
(
[CostSavingRoutes] => 1
[RailCostSaving] => 150
[Costsavingshipments] => 2
)
[origin_city] => Array
(
[origin_pcode] => 3170
)
[dest_city] => Array
(
[dest_pcode] => 4670
)
)
[2] => Array
(
[u_data] => Array
(
[totalcharge] => 15
[RoadTotal] => 15
)
)
[3] => Array
(
[u_data] => Array
(
[totalcharge] => 15
[RoadTotal] => 15
)
)
)
try 'array_merge_recursive' –
こんにちは私は私の質問でarray_merge_recursiveの出力を追加しました......しかし、私はwant..plzヘルプとして私の結果を得ていません.. –
@ testdesk私の答えをチェックしてください。 – Monty