PHP implements the method of converting indexed associative data in arrays into JSON objects, data conversion json_php Tutorial

Source: Internet
Author: User

PHP implements the method of converting indexed associative data in arrays into JSON objects, data conversion JSON


In this paper, we describe the method of transforming indexed associative data into JSON objects in a PHP implementation array. Share to everyone for your reference. The 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 ' ERROR unknown type, not yet resolved ';     Yii::app ()->end ();    }   }   break;  Case ' object ': Break   ;} return $json;}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1028965.html www.bkjia.com true http://www.bkjia.com/PHPjc/1028965.html techarticle PHP implements the method of transforming indexed associative data into JSON objects in an array, and the data conversion JSON example describes how to convert indexed associative data in a PHP implementation array into a JSON object. Share to the big ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.