Conversion of PHP objects and arrays to each other

Source: Internet
Author: User
Object and array of mutual transformation in development is also very common, generally not multidimensional case direct (array) and (object) can be done, multidimensional words, traversal can also be:


    /** * Object and Array conversions * @link http://www.phpddt.com php sharing Platform * * classTest{ Public$a; Public$b; Public function__construct($a) {$this->a =$a; }}//object to array, using Get_object_vars to return an array of object properties functionobjecttoarray($obj){$arr= Is_object ($obj) ? Get_object_vars ($obj) :$obj;if(Is_array ($arr)){returnArray_map (__function__,$arr); }Else{return$arr; }}//Array to Object functionarraytoobject($arr){if(Is_array ($arr)){return(object) Array_map (__function__,$arr); }Else{return$arr; }}$test=NewTest (' test1 ');$test->b =NewTest (' Test2 ');p Rint_r ($test);$array= Objecttoarray ($test);p Rint_r ($array);$object= Arraytoobject ($array);p Rint_r ($object);

Original address ...

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP objects and arrays of mutual transformation, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.