Answer the question
In order to leave comments, you need to log in
How to iterate over two arrays at the same time?
You need to loop through the array to display the desired values.
$result = [
"CARS" => [
"[email protected]" => ["name" => "Tesla Model X", "year" => "2012"],
"[email protected]" => ["name" => "Ford Mustang","year" => "1965"],
"[email protected]" => ["name" => "Camaro SS","year" => "1961"],
],
"BOOKS" => [
["bookName" => "Tesla Rules", "authorEmail" => "[email protected]"],
["bookName" => "Ford Mustang Rules", "authorEmail" => "[email protected]"],
["bookName" => "Camaro SS rules", "authorEmail" => "[email protected]"],
],
];
Answer the question
In order to leave comments, you need to log in
The array_map function can operate on more than one array:
echo implode('<br>', array_map(function($n, $i) use(&$result) {
return
"Книгу ".$result['BOOKS'][$i]['bookName'].
" написали для машины ".$n['name']." в ".$n['year'].
" году, можно заказать по электронной почте ".$result['BOOKS'][$i]['authorEmail'];
}, $result['CARS'], array_keys($result['BOOKS'])));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question