Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Created May 21, 2018 08:28
Show Gist options
  • Save HavenShen/c50ab3cdb74cef4bf63908ea0a1d915a to your computer and use it in GitHub Desktop.
Save HavenShen/c50ab3cdb74cef4bf63908ea0a1d915a to your computer and use it in GitHub Desktop.
一个效率非常快的把数组转对象的方法。
<?php
/*
|--------------------------------------------------------------------------
| 快速数组转对象
|--------------------------------------------------------------------------
|
| 一个效率非常快的把数组转对象的方法。
|
*/
$array = [
'name' => 'Haven Shen',
'bag' => [
'Bread',
'Tea',
'Milk'
]
];
function toObject($array)
{
return json_decode(json_encode($array));
}
print_r(toObject($array));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment