php数据还原

php数据还原存入数据库示意uniqueCode为每节课的编码(以区分courseID重复的情景,表示唯一性),actionsIndex表示{ "actions":[…], "singleTime":"30", "restTime&

大家好,欢迎来到IT知识分享网。

源数据:
{ "openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ", "courseID": "EC A7 D5 95", "courseName": "tiandizhijian", "studentCount": "2", "parts": [{ "actions": [{ "typeID": "30" }, { "typeID": "30" } ], "singleTime": "30", "restTime": "60" }, { "actions": [{ "typeID": "30" }, { "typeID": "30" } ], "singleTime": "30", "restTime": "60" } ] }

 存入数据库示意 php数据还原

uniqueCode为每节课的编码(以区分courseID重复的情景,表示唯一性),actionsIndex表示

{
“actions”: […],
“singleTime”: “30”,
“restTime”: “60”
}
这段数据在parts中的下标,为取数据时辨别typeID的分组作个标识

 

select数据之后数据为:

[{
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "E2EFE01E18F90861C667CED170552FC3",
	"courseID": "51 5D 49 F3",
	"courseName": "\u5927\u660e",
	"studentCount": "2",
	"actionsIndex": "0",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "1"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "E2EFE01E18F90861C667CED170552FC3",
	"courseID": "51 5D 49 F3",
	"courseName": "\u5927\u660e",
	"studentCount": "2",
	"actionsIndex": "0",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "3"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "E2EFE01E18F90861C667CED170552FC3",
	"courseID": "51 5D 49 F3",
	"courseName": "\u5927\u660e",
	"studentCount": "2",
	"actionsIndex": "1",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "5"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "E2EFE01E18F90861C667CED170552FC3",
	"courseID": "51 5D 49 F3",
	"courseName": "\u5927\u660e",
	"studentCount": "2",
	"actionsIndex": "1",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "7"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "0",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "1"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "0",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "3"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "0",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "5"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "1",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "7"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "1",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "2"
}, {
	"openID": "ouGzJv7G23rRCC0Bt70e1JLM70yQ",
	"uniqueCode": "8875ED583EFCB51A3603FE22309AA57F",
	"courseID": "66 6A CC 98",
	"courseName": "\u4e1c\u6b27\u4e1c",
	"studentCount": "6",
	"actionsIndex": "1",
	"singleTime": "30",
	"restTime": "60",
	"typeID": "4"
}]

  

将这些数据变为源数据的格式返回?

$arr = array();
		foreach ($res as $key) {
			# code...
			if(!array_key_exists($key->courseid ,$arr)){
				$arr[$key->courseid] = array();
				$arr[$key->courseid]['actions'] = array();
			}
			$arr[$key->courseid]['courseID'] = $key->courseid;
			$arr[$key->courseid]['courseName'] = $key->courseName;
			$arr[$key->courseid]['usageCount'] = $key->usageCount;
			
			$a = [
				"typeID" => $key->typeID,
				"setCount" => $key->setCount,
				"countPerSet" => $key->countPerSet,
				"timeInterval" => $key->timeInterval,
			];
			array_push($arr[$key->courseid]['actions'], $a);
		}
		$res = array();
		foreach ($arr as $key => $value) {
			# code...
			array_push($res, $value);
		}
		$obj = new stdClass();
		$obj->lessons = $res;
          //$obj为返回数据

  

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/33588.html

(0)
上一篇 2023-12-18 08:15
下一篇 2023-12-18 16:15

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信