Created
January 14, 2017 00:48
-
-
Save 5a494d/cc1e9ec41f646f8c7450cbb1f78238df to your computer and use it in GitHub Desktop.
Convert array to php
This file contains hidden or 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 | |
# Simple loop copy - not recursive | |
function loop_copy($array) { | |
$object = new stdClass(); | |
foreach ($array as $key => $value) { | |
$object->$key = $value; | |
} | |
} | |
# leveraging json_decode + json_encode - recursive | |
function json_copy($array) { | |
json_decode(json_encode($array), FALSE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment