Answer the question
In order to leave comments, you need to log in
Replacing php array element key with value of another element?
Hello!
Tell me how to solve such a problem, otherwise I have already broken my whole head.
I have an associative array:
array(2) {
["avto"]=>
array(2) {
[0]=>
array(2) {
["marka"]=>
string(4) "Opel"
["model"]=>
string(5) "Kadet"
}
[1]=>
array(2) {
["marka"]=>
string(3) "BMW"
["model"]=>
string(3) "520"
}
}
["kontakt"]=>
array(2) {
[0]=>
array(2) {
["tel"]=>
string(17) "+7(908) 457-40-22"
["mail"]=>
string(13) "[email protected]"
}
[1]=>
array(2) {
["tel"]=>
string(17) "+7(908) 455-10-02"
["mail"]=>
string(18) "[email protected]"
}
}
}
Answer the question
In order to leave comments, you need to log in
$array = [
'avto' => [
[
'marka' => 'Opel',
'model' => 'Kaded',
],
[
'marka' => 'BMW',
'model' => '520',
]
],
'kontakt' => [
[
'tel' => '+7(908) 457-40-22',
'mail' => '[email protected]',
],
[
'tel' => '+7(908) 455-10-02',
'mail' => '[email protected]',
]
]
];
$array['avto'] = array_combine(array_column($array['kontakt'], 'mail'), $array['avto']);
print_r($array);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question