1
我有一个数组,看起来像这样:插入数组多维数组
{"calendar":{"date":"1","event":"1","description":"","code":"lab"}}
我想输入一个新的数组到这个阵列,但里面日历来实现这样的输出:
{"calendar":
{"date":"1","event":"1","description":"","code":"lab"}
{"date":"2","event":"2","description":"","code":"lab"}
}
这一切都发生在一个表单发布。
<?php
$dy_date = $_GET['dy_date'];
$dy_event = $_GET['dy_event'];
$dy_description = $_GET['dy_description'];
$dy_code = $_GET['dy_code'];
$calendar = array("calendar" => array("date" => $dy_date, "event" => $dy_event, "description" => $dy_description, "code"=> $dy_code));
$calendar_check = json_decode(file_get_contents('../calendar_dynamic.js'),true);
$updated_cal = array();
foreach($calendar_check as $data){
$updated_cal["date"] = $dy_date;
$updated_cal["event"] = $dy_event;
$updated_cal["description"] = $dy_description;
$updated_cal["code"] = $dy_code;
$updated_cal = array_merge($calendar_check['calendar'], $updated_cal);
$filename = "../calendar_dynamic.js";
file_put_contents($filename, json_encode($updated_cal), FILE_APPEND);
}
?>
我似乎不能将添加的数组合并到现有数组中的正确位置。
想法?
谢谢像魅力一样工作。 – JMP 2013-03-21 18:58:48
不客气。 – itsid 2013-03-23 00:38:21