From 9c37ff49a6466be2dd778afc0fac943cb8a56e14 Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Sat, 10 Dec 2022 14:45:54 +0100 Subject: [PATCH] Part on Functions finished --- index.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index da41818..bcf87ff 100644 --- a/index.php +++ b/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; + } ?> - + \ No newline at end of file