Answer the question
In order to leave comments, you need to log in
Why is only 2 items displayed instead of 3?
here is the code itself. for some reason it displays only 2 books instead of 3. what's wrong? thanks in advance
<?php
$result3 = [
'authors' => [
'[email protected]' => [
'fio' => 'Ernst Hemingway',
'birthYear' => '1899',
],
'[email protected]' => [
'fio' => 'Jean Paul Sartre',
'birthYear' => '1905',
],
'[email protected]' => [
'fio' => 'Wilkie Collins',
'birthYear' => '1824',
],
],
'books' => [
[
'name' => 'The old man and the sea',
'email' => '[email protected]',
],
[
'name' => 'La Nausée',
'email' => '[email protected]',
],
[
'name' => 'The Moonstone',
'email' => '[email protected]',
],
]
];
$result = '';
$books = $result3['books'];
$authors = $result3['authors'];
foreach( $books as $item)
{
$name = $item['name'];
$email = $item['email'];
if( isset( $authors[ $email ] ) )
{
$fio = $authors[ $email ]['fio'];
$birthYear = $authors[ $email ]['birthYear'];
$result .= "Книга {$name} ее написал {$fio} {$birthYear} ({$email})<br>";
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question