Answer the question
In order to leave comments, you need to log in
How to rename keys in an array?
Hello everyone
, I have an array like this:
Array
(
[0] => красный
[1] => синий
[4] => зелёный
)
Array
(
[0] => red
[1] => blue
[4] => green
)
Answer the question
In order to leave comments, you need to log in
$translations = ['красный' => 'red', 'синий' => 'blue', 'зелёный' => 'green'];
$input = [0 => 'красный', 1 => 'синий', 4 => 'зелёный'];
foreach ($input as $k => $v) {
isset($translations[$v]) && $input[$k] = $translations[$v];
}
print_r($input);
/*
Array
(
[0] => red
[1] => blue
[4] => green
)
*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question