About the operation of php objects

WBOY
Release: 2016-08-26 10:28:24
Original
1040 people have browsed it

About the operation of php objects

I want to take out the underlined part of object
id, slot_id, update_time, create_time

Thank you everyone

Reply content:

About the operation of php objects

I want to take out the underlined part of object
id, slot_id, update_time, create_time

Thank you everyone

This is a very simple answer. Just write a method to format this object and convert it into an array. I will provide you with this method,

function object_to_array($obj) { $arr = array(); $_arr = is_object($obj)? get_object_vars($obj) : $obj; foreach ((array)$_arr as $key => $val) { $val = (is_array($val)) || is_object($val) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr; }
Copy after login

This is the result of executingsqlquery! Why didn't you set the format of the returned array? If you don’t have to choose it like this, you can also use it, such asobject->_result[0]['id']and so on, give it a try

Just look at this array$arr[0]['id'].
But your array is protected and cannot be taken out.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!