2016-06-15 15 views
2

私は3つの直列化されたデータ構造を持っています。配列にシリアル化されたデータを追加する - PHP

a:2:{i:0;s:151:"[["1","0","0","1","0","0","1","0","1","0","0","0"],["1","0","0","0","1","0","0","0","1","0","1","1"],["1","0","1","0","1","0","1","0","1","0","0","1"]]";i:1;s:151:"[["1","0","1","0","1","0","1","0","1","0","1","0"],["1","0","1","0","1","1","0","1","0","1","0","1"],["1","0","1","0","1","0","1","1","1","0","1","1"]]";} 


a:2:{i:0;s:163:"[["10","0","0","0","30","0","0","60","0","0","0","0"],["20","0","0","30","0","0","20","0","0","0","50","0"],["30","0","0","0","20","0","0","30","0","20","0","30"]]";i:1;s:154:"[["20","0","0","0","0","0","0","0","0","0","0","0"],["30","0","0","0","0","0","0","0","0","0","0","0"],["40","0","0","0","0","0","0","0","0","0","0","0"]]";} 


a:4:{i:0;s:151:"[["1","0","0","1","0","0","1","0","1","0","0","0"],["1","0","0","0","1","0","0","0","1","0","1","1"],["1","0","1","0","1","0","1","0","1","0","0","1"]]";i:1;s:151:"[["1","0","1","0","1","0","1","0","1","0","1","0"],["1","0","1","0","1","1","0","1","0","1","0","1"],["1","0","1","0","1","0","1","1","1","0","1","1"]]";i:2;s:151:"[["1","1","1","0","1","1","1","0","0","0","1","1"],["1","1","1","0","0","1","1","1","1","0","1","1"],["1","1","1","1","0","0","1","1","1","1","1","1"]]";i:3;s:151:"[["1","0","1","0","0","0","1","0","1","0","0","2"],["1","0","0","2","1","0","1","0","1","1","0","1"],["1","0","2","1","1","1","0","1","0","1","1","1"]]";} 

私は、単一のシリアル化さarrayにすべての3つのシリアル化されたデータを追加したいです。

私はこのコードとその作業を試みましたが、追加データを追加できるようにしたいと考えています。バック

$data2=unserialize($value['monthly_forecast']); 
$data1=unserialize($temp['monthly_forecast']); 
//print_r($data1); 
$combinedData = array($data1, $data2); 
$monthly_forecast=serialize($combinedData); 
$temp['monthly_forecast']=$monthly_forecast; 
+3

を。それらを組み合わせる。それを再度シリアライズする –

+0

「それらを組み合わせる」とはどういう意味ですか?それらをマージするか、それらを含む配列を作成しますか? – apokryfos

+0

[シリアル化](http://stackoverflow.com/a/1817545/5139148)のリンクを確認してください。この質問はすでに回答済みです –

答えて

0

何についてunserialize、その後array_merge()、その後serializeマージされた配列? array_merge()がそのように、あなたの場合はそれを適用することができるはずマージ

に1つまたは複数のアレイ

を使用できることに注意してください。

編集:

あなたはオプションのカップルを持っています。 unserializemergeのいずれかをすべて1つの配列に入れてからserializeとすることができます。それとも、あなたができるも:

$array = array($serialized_data_1, $serialized_data_2, $serialized_data_3); 
$all_serialized = serialize($array); 

そして、データにアクセスするには:それらアンシリアライズ

$all_unserialized = unserialize($array); 
$unserialized_data_1 = unserialize(all_unserialized[0]); 
$unserialized_data_2 = unserialize(all_unserialized[1]); 
$unserialized_data_3 = unserialize(all_unserialized[2]); 
+0

しかし、私もシリアル化データを追加したい。 –

関連する問題