Part on Functions finished
This commit is contained in:
parent
10571ef7db
commit
9c37ff49a6
1 changed files with 24 additions and 4 deletions
28
index.php
28
index.php
|
|
@ -13,21 +13,41 @@
|
|||
[
|
||||
'name' => 'Do Androids Dream of Electric Sheep',
|
||||
'author' => 'Philip K. Dick',
|
||||
'releaseYear' => 1968,
|
||||
'purchaseUrl' =>'http://example.com'
|
||||
],
|
||||
[
|
||||
'name' => 'Projekt Hail Mary',
|
||||
'author' => 'Ady Weir',
|
||||
'author' => 'Andy Weir',
|
||||
'releaseYear' => 2021,
|
||||
'purchaseUrl' => 'http://example.com'
|
||||
],
|
||||
[
|
||||
'name' => 'The Martian',
|
||||
'author' => 'Andy Weir',
|
||||
'releaseYear' => 2011,
|
||||
'purchaseUrl' => 'http://example.com'
|
||||
]
|
||||
];
|
||||
|
||||
function filterByAuthor($books, $author){
|
||||
$filteredBooks = [];
|
||||
foreach($books as $book) {
|
||||
if ($book['author'] === $author) {
|
||||
$filteredBooks[] = $book;
|
||||
}
|
||||
}
|
||||
return $filteredBooks;
|
||||
}
|
||||
?>
|
||||
<?php foreach($books as $book): ?>
|
||||
<ul>
|
||||
<?php foreach(filterByAuthor($books, 'Philip K. Dick') as $book): ?>
|
||||
<li>
|
||||
<a href="<?= $book['purchaseUrl']; ?>">
|
||||
<?= $book['name']; ?>
|
||||
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue