Created
May 21, 2018 08:28
-
-
Save HavenShen/c50ab3cdb74cef4bf63908ea0a1d915a to your computer and use it in GitHub Desktop.
一个效率非常快的把数组转对象的方法。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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