3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allLanguages = ['en', 'es', 'fr']; $values = ['es' => 'Spanish1']; $filesContent = [ 'foo' => [ 'es' => ['bar' => 'Spanish2'], 'fr' => ['bar' => 'French'] ] ]; $fileName = 'foo'; $key = 'bar'; $original = []; foreach ($allLanguages as $languageKey) { $original[$languageKey] = $values[$languageKey] ?? $filesContent[$fileName][$languageKey][$key] ?? ''; } var_export($original);

preferences:
29.81 ms | 404 KiB | 5 Q