Home > php教程 > PHP源码 > JSON取出及修改

JSON取出及修改

PHP中文网
Release: 2016-05-22 18:26:59
Original
971 people have browsed it

很多地方存放内容不再是单一值,而是很多数据合并后存放在一个字段里,为了更方便取出来更新或者再增加,于是写了一个结构函数,程序会持续优化,记录下来备用:
大家指点下,代码写的不好请各位指教;

	function editor_json_code($array, $code, $aid) {
		if(empty($code) OR empty($aid)) {
			return $array;
		}
		$json = json_decode($array, true);
		foreach($json as $key => $value) {
			if($key == $code) {
				$var[$key] = $aid;
			} else {
				$var[$key] = $value;
			}
		}
		if(!preg_match("/$code/", $array)) {
			$var[$code] = $aid;
		}
		return json_encode($var);
	}
Copy after login

                   

 以上就是JSON取出及修改的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Backslash present in Json
From 1970-01-01 08:00:00
0
0
0
Get: Transfer JSON data
From 1970-01-01 08:00:00
0
0
0
mysql storage json error
From 1970-01-01 08:00:00
0
0
0
javascript - Problems with displaying json data
From 1970-01-01 08:00:00
0
0
0
Find matching integers in JSON.
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template