Part on Lambda Functions finished
This commit is contained in:
parent
9c37ff49a6
commit
a45a77f0ae
1 changed files with 4 additions and 10 deletions
14
index.php
14
index.php
|
|
@ -29,19 +29,13 @@
|
||||||
'purchaseUrl' => 'http://example.com'
|
'purchaseUrl' => 'http://example.com'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
$filteredItems = array_filter($books, function($book) {
|
||||||
|
return $book['author'] == 'Andy Weir';
|
||||||
|
});
|
||||||
|
|
||||||
function filterByAuthor($books, $author){
|
|
||||||
$filteredBooks = [];
|
|
||||||
foreach($books as $book) {
|
|
||||||
if ($book['author'] === $author) {
|
|
||||||
$filteredBooks[] = $book;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $filteredBooks;
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach(filterByAuthor($books, 'Philip K. Dick') as $book): ?>
|
<?php foreach($filteredItems as $book): ?>
|
||||||
<li>
|
<li>
|
||||||
<a href="<?= $book['purchaseUrl']; ?>">
|
<a href="<?= $book['purchaseUrl']; ?>">
|
||||||
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
|
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue