PHP converts an array of objects into a normal array

Source: Internet
Author: User

Don't know why, serialize the array to JSON, and then save it to Redis (string type). And then take it out and deserialize it into an array, it becomes an array of objects.

thinkphp Normal array value $arr[' key '] object array $arr->key

1 /**2 * [Std_class_object_to_array object to group]3 * @param [Stdclass] $stdclassobject [Object]4 * @return [array] [arrays]5 */6 functionStd_class_object_to_array ($stdclassobject)7 {8     $_array=Is_object($stdclassobject) ?Get_object_vars($stdclassobject) :$stdclassobject;9 Ten     foreach($_array  as $key=$value) { One       $value= (Is_array($value) ||Is_object($value)) ? Std_class_object_to_array ($value) :$value; A       $array[$key] =$value; - } -  the     return $array; -}
View Code

//Call this function, transform it into an array, and then remove the corresponding valuefunctionObject_array ($array){   if(Is_object($array))   {    $array= (Array)$array; }   if(Is_array($array))   {    foreach($array  as $key=$value)    {     $array[$key] = Object_array ($value); }   }   return $array;}

PHP converts an array of objects into a normal array

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.