Last active
March 24, 2026 10:45
-
-
Save JeffreyWay/40fcd41c03de5805aedc62ac847094df to your computer and use it in GitHub Desktop.
PHP For Beginners, Episode 7 - Associative Arrays https://laracasts.com/series/php-for-beginners-2023-edition/episodes/7
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> | |
| <?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' | |
| ] | |
| ]; | |
| ?> | |
| <ul> | |
| <?php foreach ($books as $book) : ?> | |
| <li> | |
| <a href="<?= $book['purchaseUrl'] ?>"> | |
| <?= $book['name'] ?> (<?= $book['releaseYear'] ?>) | |
| </a> | |
| </li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </body> | |
| </html> |
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> | |
| <?php | |
| $books = [ | |
| [ | |
| 'name' => 'Do Androids Dream of Electric Sheep', | |
| 'author' => 'Philip K. Dick', | |
| 'purchaseUrl' => 'http://example.com' | |
| ], | |
| [ | |
| 'name' => 'Project Hail Mary', | |
| 'author' => 'Andy Weir', | |
| 'purchaseUrl' => 'http://example.com' | |
| ] | |
| ]; | |
| ?> | |
| <ul> | |
| <?php foreach ($books as $book) : ?> | |
| <li> | |
| <a href="<?= $book['purchaseUrl'] ?>"> | |
| <?= $book['name'] ?> | |
| </a> | |
| </li> | |
| <?php endforeach; ?> | |
| </ul> | |
| </body> | |
| </html> |
$books = [
[
"name" => "Purple Hibiscus",
"author" => "Chimamanda Ngozi Adichie",
"bookUrl" => "https://bordersliteratureonline.net/books/purple-hibiscus"
],
[
"name" => "New Daughters of Africa",
"author" => "Margaret Busby",
"bookUrl" => "https://bordersliteratureonline.net/books/New-Daughters-of-Africa"
],
[
"name" => "Self in the World: Connecting Life's Extremes",
"author" => "Keith Hart",
"bookUrl" => "https://bordersliteratureonline.net/books/Keith_Hart"
]
];
foreach ($books as $book):
echo "{$book["name"]} ". "
";
echo "{$book["author"]} ". "
";
echo "{$book["bookUrl"]} ". "
";
endforeach;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?>
Release Date: