<?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);
- Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- array (
'en' => '',
'es' => 'Spanish1',
'fr' => 'French',
)
preferences:
73.18 ms | 410 KiB | 6 Q