Created
May 18, 2013 12:28
-
-
Save maximevalette/5604240 to your computer and use it in GitHub Desktop.
Merges JSON files
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 | |
$source = json_decode(file_get_contents('french.json'), true); | |
$dest = json_decode(file_get_contents('auto_french.json'), true); | |
function mergeArray($source, $dest) { | |
foreach ($dest as $k => $v) { | |
if (!array_key_exists($k, $source)) { | |
$source[$k] = $v; | |
} elseif (!is_string($v)) { | |
$source[$k] = mergeArray($source[$k], $v); | |
} | |
} | |
return $source; | |
} | |
$new = mergeArray($source, $dest); | |
file_put_contents('new_french.json', json_encode($new, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment