$slug, 'template' => [ [ 'sprite_name' => $npcData['sprite'], 'combat_front' => $npcData['sprite'], ], ], ]; if (isset($npcs[$slug])) { $npcs[$slug] = array_replace_recursive($npcs[$slug], $npc); } else { $npcs[$slug] = $npc; } } foreach ($npcs as $slug => $npc) { file_put_contents(__DIR__ . "/_generated/npc/$slug.json", json_encode($npc)); }