Example of functions for adding credits in phpjson
The code for adding points to json in php is helpful for understanding how to construct json data in php. For more information, see. The code is as follows, which is for your reference only. Function zeng_integral () {$ jifen = & m ('integral');/* determine an Internet cafe */$ store = isset ($ store_id )? Intval ($ store_id): 0; $ injifen = $ jifen-> get (array ('User _ id' = >$ _ SESSION ['User _ info'] ['User _ id']); $ yanzhen = json_decode ($ injifen ['integrallog'], true); if (isset ($ injifen) {$ arrstore = array (); foreach ($ yanzhen as $ k => $ v) {$ arrstore [] = $ v ['store _ id'];} /* determine whether points exist. if Yes */if (in_array ($ store, $ arrstore) {foreach ($ yanzhen as $ key => $ val) {$ yanzhen [$ key] ['store _ id'] = $ key; $ yanzhen [$ key] ['jifen'] = $ val ['jifen'] + 5;} $ integral = json_encode ($ yanzhen );} else {foreach ($ yanzhen as $ key => $ val) {$ yanzhen [$ store] ['store _ id'] = $ store; $ yanzhen [$ store] ['jifen'] = 1 ;}$ integral = json_encode ($ yanzhen );} /* construct data */$ data = array ('integrallog' => $ integral,); $ integ = $ jifen-> edit ($ injifen ['id'], $ data); if ($ integ) {return true ;}} else {/* constructs an array */$ config = array (); $ config [$ store] ['store _ id'] = $ store; $ config [$ store] ['jifen'] = 1; $ integral = json_encode ($ config ); /* construct data */$ data = array ('User _ id' => $ _ SESSION ['User _ info'] ['User _ id'], 'integrallog' => $ integral,); $ integ = $ jifen-> add ($ data); if ($ integ) {return true ;}}} |