Last active
October 3, 2022 18:34
-
-
Save JeffreyWay/52d403ca86885391d6048b890218f076 to your computer and use it in GitHub Desktop.
PHP for Beginners, Episode 10 - Separate Logic From the Template https://laracasts.com/series/php-for-beginners-2023-edition/episodes/10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$books = [ | |
[ | |
'name' => 'Do Androids Dream of Electric Sheep', | |
'author' => 'Philip K. Dick', | |
'releaseYear' => 1968, | |
'purchaseUrl' => 'http://example.com' | |
], | |
[ | |
'name' => 'Project Hail Mary', | |
'author' => 'Andy Weir', | |
'releaseYear' => 2021, | |
'purchaseUrl' => 'http://example.com' | |
], | |
[ | |
'name' => 'The Martian', | |
'author' => 'Andy Weir', | |
'releaseYear' => 2011, | |
'purchaseUrl' => 'http://example.com' | |
], | |
]; | |
$filteredBooks = array_filter($books, function ($book) { | |
return $book['releaseYear'] >= 1950 && $book['releaseYear'] <= 2020; | |
}); | |
require "index.view.php"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Demo</title> | |
</head> | |
<body> | |
<ul> | |
<?php foreach ($filteredBooks as $book) : ?> | |
<li> | |
<a href="<?= $book['purchaseUrl'] ?>"> | |
<?= $book['name']; ?> (<?= $book['releaseYear'] ?>) - By <?= $book['author'] ?> | |
</a> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment