Php object to array, online, etc.-php Tutorial

Source: Internet
Author: User
Php object to array, Online php object to array, the following $ images is an array to convert key and value. $ What should I do if images is an object? Online
Function change ($ images, $ a = 0 ){
Foreach ($ images as $ key => $ value ){
$ Images [$ a] [$ value ['picture _ id'] = $ value ['Local _ path'];
$ Images [$ a] ['picture _ id'] = $ value ['picture _ id'];
$ A ++;
}
Return $ images;
}

$ Arry = change ($ images );


Reply to discussion (solution)

PHP built-in arrayObject class
$ Obj = new arrayObject ($ arr );
Var_dump ($ obj );

Does the database fetch data? you don't need to convert the data, just use foreach, but the object uses $ obj-> xxx to process the value.

Does the database fetch data? you don't need to convert the data, just use foreach, but the object uses $ obj-> xxx to process the value.


You are right, but the fields required by the front-end are different. you need to rename the name of foreach.
Related Article

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.