Home  >  Article  >  Backend Development  >  About the operation of php objects

About the operation of php objects

WBOY
WBOYOriginal
2016-08-26 10:28:241111browse

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,

<code class="PHP">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;    
}</code>

This is the result of executing sqlquery! 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 as object->_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.

Statement:
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