S
S
ssvv962020-04-24 17:30:55
PHP
ssvv96, 2020-04-24 17:30:55

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

1 answer(s)
A
Andrey, 2020-04-24
@AndryG

The old man and the sea by Ernst Hemingway 1899 ([email protected])
La Nausée by Jean Paul Sartre 1905 ([email protected])
The Moonstone by Wilkie Collins 1824 ([email protected])

And I have three. The code was just copied and pasted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question