This article mainly introduces how php converts indexed associated data in arrays to json objects. based on the Yii Framework, it analyzes the conversion techniques of php arrays and json data, for more information, see the example in this article. php describes how to convert the index associated data in an array to a json object. Share it with you for your reference. The specific implementation method is as follows:
Public static function encode (& $ var) {return '{'. implode (',', self: encodeExcute ($ var )). '}';} private static function encodeExcute (& $ var) {$ json = array (); switch (gettype ($ var) {case 'array ': foreach ($ var as $ key => $ value) {if (is_array ($ value) {$ json [] = '"'. $ key. '":{'. implode (',', self: encodeExcute ($ value )). '}'; // $ json [$ key] = self: encode ($ value);} elseif (is_object ($ value )) {$ json [] = "\" {$ key }\\":". json_encode ($ value-> attributes);} else {echo 'unknown ERROR type, not resolved '; Yii: app ()-> end () ;}} break; case 'object': break;} return $ json ;}
I hope this article will help you with php programming.