From a45a77f0aeb700c8857010d0a229020558ff576d Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Sat, 10 Dec 2022 15:07:08 +0100 Subject: [PATCH] Part on Lambda Functions finished --- index.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index bcf87ff..076f418 100644 --- a/index.php +++ b/index.php @@ -29,19 +29,13 @@ '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; - } ?>