In many places, the stored content is no longer a single value, but a lot of data is merged and stored in a field. to make it easier to retrieve and update or add more data, a structure function is written, the program will be continuously optimized and recorded for backup: Please advise if the code is not well written. the content stored in many places is no longer a single value, instead, a lot of data is merged and stored in a field. in order to make it easier to retrieve and update or add more data, a structure function is written, and the program will be continuously optimized and recorded for backup:
Please advise if the code is not well written;
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 );}
The above is the JSON retrieval and modification content. For more information, see The PHP Chinese website (www.php1.cn )!