Object array Conversion

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn how to use data conversion a few days ago, and create a class to convert data.
PHP converts and serializes data into JSON data, and deserializes JSON data. In normal development, arrays and objects are sometimes used for conversion. I used it a few days ago, so we get a class to implement data conversion.
The usage is shown below:
Convert an array to an object: Public function index (){
Import ('class. object_array ', APP_PATH); // import the paging Class

$ Data = array ('name' => 'wei wei', 'age' => 15, 'sex' => 'male ', 'hobby' => 'favorite Network Worms ');
$ Obj = object_array: get_object ($ data );
P ($ obj );
}
Implementation results:

Convert an object to an array: Class TestAction extends CommonAction {

Public function index (){
Import ('class. object_array ', APP_PATH); // import the paging Class

$ Holobby ['pingpang '] = new holobby ('table tennis', '2 year ');
$ Holobby ['qifany'] = new holobby ('qifany', '6 year ');
$ Me = new Human ('wei wei', 15, 'mal', $ holobby );
$ Array = object_array: get_array ($ me );
P ($ array );
}
}
/*
Human
*/
Class Human {
Public $ name;
Public $ age;
Public $ sex;
Public $ holobby;
Public function Human ($ name, $ age, $ sex, $ holobby ){
$ This-> name = $ name;
$ This-> age = $ age;
$ This-> sex = $ sex;
$ This-> holobby = $ holobby;
}
}
/*
Hobbies
*/
Class holobby {
Public $ name;
Public $ time;
Public function holobby ($ name, $ time ){
$ This-> name = $ name;
$ This-> time = $ time;
}
}
Run:

Hope to help you a little bit, free shoes: to add a little traffic to me: http://wei416978817.byethost33.com Web Pages have updated, please provide suggestions!

Object_array.class.rar (365 B download: 56 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.