Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active May 10, 2026 02:55
Show Gist options
  • Select an option

  • Save JeffreyWay/40fcd41c03de5805aedc62ac847094df to your computer and use it in GitHub Desktop.

Select an option

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
<!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>
<!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>
@faithnapeto

Copy link
Copy Markdown
<title>Document</title> 'The smart woman money', 'author'=> 'Arese Ugwe', 'Url'=> 'eJzj4tVP1zc0TC42TSrKqow3YPQSLclIVSjOTSwqUSjPz03MU8jNz0utBADuMw0C',
],
[
    'name'=> 'The heart of leadership',
    'author'=> 'Joshua freedman',
    'Url'=> 'https://www.google.co.ke/books/edition/The_Heart_of_Leadership/KSsRO4GFZykC?hl=en&gbpv=0',

],

];
?>

        <li>
            <a href="<?= $books['Url'] ?>">
            <?= $books['name'] ?>
    </a>
    </li>
    <?php endforeach; ?>
    </ul>
    

@jcravelo

Copy link
Copy Markdown
        <?php foreach($books as $book) : ?>

        <li>    
            <a href="<?php echo $book['purchaseUrl'] ?>">
                <?php echo $book['name'].' ('.$book['year'].')';?>
            </a>
        </li>

        <?php endforeach; ?>

@Srdjan0404

Srdjan0404 commented Jul 4, 2023

Copy link
Copy Markdown
<title>Demo</title>
<style>
    body {
        display: grid;
        place-items: center;
        height: 100vh;
        margin: 0;
        font-family: sens-serif;
    }
</style>
<h1>Recommended books</h1>

<?php
    $books = [
        [
            'name' => 'Harry Potter',
            'author' => 'J. K. Rowling',
            'releaseYear' => '1997',
            'purchaseUrl' => 'http://example.com'
            
        ],
        [
            'name' => 'The Wealth of Nations ',
            'author' =>'Adam Smith',
            'releaseYear' => '1776',
            'purchaseUrl' => 'http://example.com'
            
        ],
        [
            'name' => ' Between the World and Me',
            'author' =>'Siddhartha Mukherjee',
            'releaseYear' => '2011',
            'purchaseUrl' => 'http://example.com'
            
        ],
    ];
?>

<ul>
    <?php foreach($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>"><?= "{$book['name']} ({$book['releaseYear']})"; ?></a>
        </li>
    <?php endforeach; ?>
</ul>

@mahafuzurrahmanhridoy

Copy link
Copy Markdown
<title>Laracast</title>
<?php

$books = [

    [
        'name' => 'Book 1',
        'author' => 'Robert',
        'releaseYear' => 2017,
        'purchaseUrl' => 'https://book1.com'
    ],

    [
        'name' => 'Book 2',
        'author' => 'Robertson',
        'releaseYear' => 2020,
        'purchaseUrl' => 'https://book2.com'
    ]
];
?>

<ul>
    <?php
    foreach ($books as $book) { ?>

        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
                <?= $book['name']; ?>
            </a>
        </li>

        <li>
            <?= $book['releaseYear']; ?>
        </li>
    <?php } ?>
</ul>

@UtkirbekYuldoshev96

Copy link
Copy Markdown
<title>PHP || Functions</title>
  <ul>
        <?php foreach($books as $book):?>
              <li>
                    <a href="<?=$book['url']?>">
                          <?=$book['name']?>
                    </a>
              </li>
        <?php endforeach;?>
  </ul>

@UtkirbekYuldoshev96

Copy link
Copy Markdown
'The Selection', 'author'=> 'Alice Gabriel', 'url'=> 'http:://example.com', 'year'=> '2013' ], [ 'name'=> 'The Selection 2', 'author'=> 'Alice Gabriel 2', 'url'=> 'http:://example.com', 'year'=> '2015' ], [ 'name'=> 'The Selection 3', 'author'=> 'Alice Gabriel', 'url'=> 'http:://example.com', 'year'=> '2015' ], [ 'name'=> 'The Selection 4', 'author'=> 'Gabriel', 'url'=> 'http:://example.com', 'year'=> '2015' ], [ 'name'=> 'The Selection 5', 'author'=> 'Alice ', 'url'=> 'http:://example.com', 'year'=> '2015' ] ]; ?>

@UtkirbekYuldoshev96

Copy link
Copy Markdown

*{
padding: 0;
margin: 0;
box-sizing: border-box;
}

ul li {
padding: 8px;
margin: 0 auto;
}
ul li a{
text-decoration: none;
}

@Dogukansvsl

Copy link
Copy Markdown
'Sefiller', 'auther' => 'Victor Hugo', 'releaseYear' => 1852, 'purchaseUrl' => 'https://www.dr.com.tr/Kitap/Sefiller-2-Cilt-Takim/Edebiyat/Roman/Dunya-Klasik/urunno=0000000651687', ], [ 'name' => 'Hayvan Çiftliği', 'auther' => 'George Orwell', 'releaseYear' => 1852, 'purchaseUrl' => 'https://www.dr.com.tr/kitap/hayvan-ciftligi/george-orwell/edebiyat/roman/dunya-roman/urunno=0000000105409', ] ]; ?>
    <ul> 
        <?php foreach ($books as $book) : ?>
            <li>
                
                <a href="<?= $book['purchaseUrl'] ?>">
                    <?= $book['name'] ?> (<?= $book['releaseYear']  ?>)
                </a>

            </li>
            <?php endforeach; ?> 
    </ul>

@JigokuPHP

Copy link
Copy Markdown

`

<title>Demo PHP</title>

Recommended Books

$books = [ ['name' => 'Keep it Up', 'dateRels'=> '1990', 'author' => 'brock Morris', 'buyUrl' => 'http://example.com'], ['name' => 'True GG', 'dateRels'=> '1960', 'author' => 'Haku mindra', 'buyUrl' => 'http://example-009.com'] ];

?>

  • ()
  • <?php endforeach; ?>
    
`

@hackershokirjonov

Copy link
Copy Markdown
 <?php
 $books = [
      [
           "name" => "Shum bola",
           "created_at"=> "nn.mm.aaaa",
           "author" => "Gafur Gulom",
           "purchaseUrl" => "https//kun.uz",
      ],
      [
           "name" => "Xamsa",
           "created_at"=>"xx.zz.yyyy",
           "author" => "Alisher Navoiy",
           "purchaseUrl" => "https//youtube.com",
      ]
 ]
 ?>

 <ul>
      <?php foreach ($books as $book) : ?>
           <a href="<?= $book['purchaseUrl'] ?>" style="text-decoration: none;">
                <li><?= $book['name'] . "| Yaratilgan sana:" . $book['created_at']  . "   | Yozuchi " . $book['author'] ?></li>
           </a>

      <?php endforeach;   ?>
 </ul>

@AdhiDevX369

AdhiDevX369 commented Nov 26, 2023

Copy link
Copy Markdown
<body>
    <?php
    $books = [
        [
            'name' => 'Asahara',
            'author' => 'Imesh Madhushanka Yapa',
            'urlToBuy' => 'www.buybooks.com/asahara',
            'releasedYear' => '2022'
        ],
        [
            'name' => 'Game Of thrones',
            'author' => 'George R. R. Martin',
            'urlToBuy' => 'www.buybooks.com/gameofthrones',
            'releasedYear' => '1996'
        ], [
            'name' => 'Forgot me or Not',
            'author' => 'Charitha Prawardhi Bandara, Chathuri Damayanthi',
            'urlToBuy' => 'www.buybooks.com/forgotmeornot',
            'releasedYear' => '2023'

        ], [
            'name' => 'Dark Matter',
            'author' => 'Blake Crouch',
            'urlToBuy' => 'www.buybooks.com/DarkMatter',
            'releasedYear' => '2016'

        ]
    ];
    ?>

    <ul>
        <?php foreach ($books as $book) : ?>
            <li>
                <a href="<?= $book['urlToBuy']; ?>">
                    <?= $book['name']; ?>
                </a>
                <?= $book['releasedYear']; ?>
            </li>
        (<?php endforeach; ?>)
    </ul>
</body>
</html>

@Shimazaky80

Copy link
Copy Markdown

My solution:

`

<title>Demo</title> <style> body { display: grid; place-items: center; /* height: 100vh; */ margin: 0; font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; } </style>
<h1>Recommended Books</h1>

<?php
    // List of recommended books
    $books = [

        [
            "name" => "Do Androids Dream of Electric Sheep",
            "releaseYear" => 1968,
            "author" => "Philip K. Dick",
            "purchaseUrl" => "http://example.com"
        ],
        [
            "name" => "The Langoliers",
            "releaseYear" => 1995,
            "author" => "Andy Weir",
            "purchaseUrl" => "http://example.com"
        ],
        [
            "name" => "Project Hail Mary",
            "releaseYear" => 2021,
            "author" => "Jonh Doe",
            "purchaseUrl" => "http://example.com"
        ],
        [
            "name" => "Animal Farm",
            "releaseYear" => 1945,
            "author" => "Another Jonh Doe",
            "purchaseUrl" => "http://example.com"
        ]
        
    ];
?>

<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book["purchaseUrl"] ?>">
                <?= $book["name"] ?>
                (<?= $book["releaseYear"] ?>)
            </a>
        </li>
    <?php endforeach; ?>
</ul>
`

@spacemark3

Copy link
Copy Markdown

<?php $books = [ [ 'name' =>'Do Androids Dream of Electric Sheep', 'year' => '1980', 'author' => 'Philip K. Dick', 'purchaseUrl' =>'http://example1.com' ], [ 'name' => 'Project Hail Mary', 'year' => '2000', 'author' => 'Andy Weir', 'purchaseUrl' => 'http://example2.com' ], [ 'name' => 'The Langoliers', 'year' => '1950', 'author' => 'Mark Andro', 'purchaseUrl' => 'http://example3.com' ], [ 'name' => 'The shadow of the wind', 'year' => '2001', 'author' => 'Carlos Ruiz Zafon', 'purchaseUrl' => 'http://example4.com' ], ]; ?> <ul> <?php foreach($books as $book) : ?> <li> <a href="<?= $book['purchaseUrl'] ?>"> <?= $book['name']; ?> <?= $book['year']; ?> </a> </li> <?php endforeach; ?> </ul>

@K1LLERB0T

Copy link
Copy Markdown

<h1>Recommended Books</h1>
<?php
    $books = [
        [
            'name' => 'Do Androids Dream of Electric Sheep?',
            'author' => 'Phillip K. Dick',
            'releaseYear' => '1968',
            'purchaseUrl' => 'example.com'
        ],
        [
            'name' => 'The Langoliers',
            'author' => 'Stephen King',
            'releaseYear' => '1990',
            'purchaseUrl' => 'example.com'
        ],
        [
            'name' => 'Project Hail Mary',
            'author' => 'Andy Weir',
            'releaseYear' => '2021',
            'purchaseUrl' => 'example.com'
        ]
    ]
?>

<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
            <?= $book['name']; ?>
            </a>
            <?= $book['releaseYear']; ?>
        </li> 
    <?php endforeach; ?>
</ul>

@Mickish1

Mickish1 commented Apr 29, 2024

Copy link
Copy Markdown
<title>FUN STUFFS</title>

Recommended List

'Do Androids Dream of Electric Sheep', 'author' => 'John Doe', 'purchaseUrl' => 'http://pavilion.com', 'releaseDate' => '2024' ], ['name' => 'The Extremist', 'author' => 'Michael Fasina', 'purchaseUrl' => 'http://pavilion.com', 'releaseDate' => '2021'], ['name' => 'Project Hail Mary', 'author' => 'Andy Weir', 'purchaseUrl' => 'http://fashmichael.com', 'releaseDate' => '2022' ] ] ?>

ghost commented Jul 1, 2024

Copy link
Copy Markdown
<!doctype html>
<html lang="en">
<head>
    <title>Demo</title>
    <meta charset="UTF-8">
</head>
<body>

<h1>Recommended Books</h1>

<?php
    $books = [
            [
                    'name' => 'Do Androids Dream of Electric Sheep',
                    'author' => 'Philip K. Dick',
                    'releaseYear' => 1968,
                    'purchaseUrl' => 'https://example.com'
            ],
            [
                    'name' => "Project Hail Mary",
                    'author' => "Andy Weir",
                    'releaseYear' => 2021,
                    'purchaseUrl' => "https://example.com"
            ]
    ];
?>

<ul>
    <?php foreach($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
            <?= $book['name'] ?> (<?= $book['releaseYear'] ?>)
            </a>
            - <?= $book['author'] ?>
        </li>
    <?php endforeach; ?>
</ul>

</body>
</html>

@Rofiaziztr

Copy link
Copy Markdown

<!doctype html>

<title>Demo</title> 'The Psychology of Money', 'author' => 'Morgan Housel', 'releaseDate' => '2020', 'purchaseUrl' => 'http://example.com' ], [ 'name' => 'Introducing Web Development', 'author' => 'Jörg Krause', 'releaseDate' => '2016', 'purchaseUrl' => 'http://example.com' ] ]; ?>
<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
                <?= $book['name'].' '.$book['releaseDate'] ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

@Mkleon

Mkleon commented Jul 26, 2024

Copy link
Copy Markdown
<title>Demo</title>

Recommended Books

<?php 
    $books = [
        [
            'name' => "Do Androids Dream of Electric Sheep",
            'author' => "Philip K.Dick",
            'purchaseUrl' => "http://example.com",
            'releaseYear' => "2023"
        ],
        [
            'name' => "The Langoliers",
            'author' => "Andry Weir",
            'purchaseUrl' => "http://example.com",
            'releaseYear' => "2018"
        ]
    ];
?>

<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl']; ?>">
                <?= "{$book['name']} ({$book['releaseYear']})"; ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

@laurencetroyv

Copy link
Copy Markdown
<?php 
    $books = [
        [
            'name' => "One Piece",
            'author' => "Eiichiro Oda",
            'purchaseUrl' => "http://example.com",
            'releasedYear' => "1997"
        ],
        [
            'name' => "Inuyasha",
            'author' => "Takahashi, Rumiko",
            'purchaseUrl' => "http://example.com",
            'releasedYear' => "1998"
        ]
    ];
?>

<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl']; ?>">
                <?= "{$book['name']} ({$book['releasedYear']})"; ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

@laurencetroyv

laurencetroyv commented Aug 9, 2024

Copy link
Copy Markdown
<?php 
    $books = [
        [
            'name' => "One Piece",
            'author' => "Eiichiro Oda",
            'purchaseUrl' => "http://example.com",
            'releasedYear' => 1997
        ],
        [
            'name' => "Inuyasha",
            'author' => "Takahashi, Rumiko",
            'purchaseUrl' => "http://example.com",
            'releaseYear' => 1998
        ]
    ];
?>

<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl']; ?>">
                <?= "{$book['name']} ({$book['releaseYear']})"; ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

@Sajjalh7

Copy link
Copy Markdown
'Sajjal Book', 'Author'=> 'Sajjal Hmgn', 'releaseYear' => 2007, 'purchaseUrl' => 'https://example.com' ], [ 'Name'=> 'Sajjal other Book', 'Author'=> 'Sajjal Hmgn2', 'releaseYear' => 2001, 'purchaseUrl' => 'https://example.com' ], ]; ?>

@ShinjiX-Web

ShinjiX-Web commented Aug 24, 2024

Copy link
Copy Markdown

Just trying this...

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="/styles.css" />
  <link href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAzMzMA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAABAAEAEBAAAAEAAQAQEAAAAQABABAQAAABAAEAEBAAAAERAREQERAAAQEBABAQEAABAQEAEBAQAAEBAQAQEBAAAREBABAREAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" rel="icon" type="image/x-icon">
  <title>PHP Sample</title>
</head>

<body>
  <div class="container">

    <div class="sub-container">
      <h1>

        <?php

        $name = "The Dark Matter!";
        $read = false;

        if ($read) {
          $message = "You have read $name";
        } else {
          $message = "You have not read $name";
        }

        echo $message;

        ?>

      </h1>

      <h2>Recommended Books</h2>

      <?php
      $books =
        [
          [
            'name' => "The Orly Farm",
            'author' => "John",
            'releaseYear' => 2000,
            'url' => "https://laracasts.com/"
          ],
          [
            'name' => "Magneto Revenge",
            'author' => "Will Smith",
            'releaseYear' => 1987,
            'url' => "https://laracasts.com/"
          ]
        ];
      ?>

      <div class="mini-container">
        <ul>
          <?php foreach ($books as $book) : ?>
            <li>
              <a href="<?= $book['url'] ?>" target="_blank">
                <?= $book['name']; ?> (<?= $book['releaseYear'] ?>)
              </a>
            </li>
          <?php endforeach; ?>
        </ul>
      </div>
    </div>
  </div>
</body>

</html>

php_photo

@kwekuduahh

kwekuduahh commented Aug 27, 2024

Copy link
Copy Markdown
"Crossover", "director" => "James Cameron", "year" => 2010 ], [ "title" => "The Death Square", "director" => "Fredrick Afful", "year" => 2018 ], [ "title" => "The Hobbit", "director" => "David Camelot", "year" => 2017 ], [ "title" => "Fast X", "director" => "Daniel Glover", "year" => 2020 ] ] ?>
<h2>Movies Recommendations (Year)</h2>
<ul>
    <?php foreach ($Movies as $movie) :?>
        <li><?= $movie['title']." (".$movie['year'].")"; ?></li>
    <?php endforeach;?>
</ul>

@CaioCesarP

Copy link
Copy Markdown
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Books</title>
</head>

<style>
  body {
    font-family: Arial, sans-serif;
  }

  container {
    display: grid;
    place-items: center;
  }

</style>

<body>
  <?php
    $books = [
      [
        "id" => 1,
        "cover" => null,
        "name" => "Dark Matter",
        "author" => "Blake Crouch",
        "releaseYear" => 2016,
        "purchaseUrl" => "http://example.com",
        "summary" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel nisi nec velit consectetur dignissim. In non ipsum sed ipsum gravida tristique. Sed euismod, enim ut pulvinar cursus, nisi felis rutrum ex, id viverra justo felis non massa.",
        "readed" => false,
        "rating" => 4.8
      ],
      [
        "id" => 2,
        "cover" => null,
        "name" => "The Catcher in the Rye",
        "author" => "J. D. Salinger",
        "releaseYear" => 1951,
        "purchaseUrl" => "http://example.com",
        "summary" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel nisi nec velit consectetur dignissim. In non ipsum sed ipsum gravida tristique. Sed euismod, enim ut pulvinar cursus, nisi felis rutrum ex, id viverra justo felis non massa.",
        "readed" => true,
        "rating" => 4.8
      ],
      [
        "id" => 3,
        "cover" => null,
        "name" => "To Kill a Mockingbird",
        "author" => "Harper Lee",
        "releaseYear" => 1960,
        "purchaseUrl" => "http://example.com",
        "summary" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel nisi nec velit consectetur dignissim. In non ipsum sed ipsum gravida tristique. Sed euismod, enim ut pulvinar cursus, nisi felis rutrum ex, id viverra justo felis non massa.",
        "readed" => false,
        "rating" => 3.7,
      ],
    ];
  ?>

  <div class="container">
    <ul class="books list">
      <?php foreach ($books as $book) :?>
        <li id="book-<?= $book['id'];?>" class="book">
          <div id="book-cover"><?= $book['cover']?></div>
          <a class="book-name" href="<?= $book['purchaseUrl'];?>">
            <?= $book['name'];?> (<?= $book['releaseYear'];?>)
          </a>
          <p class="book-summary"><?= $book['summary'];?></p>
          <p class="book-rating">Rating: <?= $book['rating'];?></p>
          <div class="book-controls">
            <input type="checkbox" class="book-read-checkbox" <?= $book['readed']? 'checked' : '';?>>
            <label for="book-read-checkbox">Read</label>
          </div>
        </li>
      <?php endforeach;?>
    </ul>
    </ul>
  </div>

</body>

</html>

@ta-riq

ta-riq commented Feb 20, 2025

Copy link
Copy Markdown
<!DOCTYPE html>

<head>
    <title>Learn PHP</title>
    <style>
        body {
            display: grid;
            place-Items : center;
            height: 100vh;
            font-size: 25px;
            margin: 0;
        }
    </style>
</head>
<body>
        <?php 

        $books = [
            [
                'name' => "Masud Rana",
                'author' =>  "Kazi Anowar Hossain",
                'purchaseUrl' => "https://example.com"
            ],
            [
                'name' => "Tin Goyenda",
                'author' => "Shamsuddin Nawab",
                'purchaseUrl' => "https://example2.com"
            ]
        ];

        ?>

        <ul>
            <?php foreach($books as $book) : ?>
            <li>
                <h3>Name: <?= $book["name"] ?></h3>
                <p>Author: <?= $book["author"] ?> </p>
                <a href="<?= $book['purchaseUrl'] ?>">
                    Buy Now        
                </a>
            </li>
            <?php endforeach; ?>
        </ul>

</body>

</html>

@cH0NKIIs34L

Copy link
Copy Markdown
<?php

/* __________________________________________________
Keys and Values
Echo the value that is associated with the book's name key.
*/
$book = [
	'name' => 'Do Androids Dream of Electric Sheep',
	'author' => 'Philip K. Dick',
	'purchaseUrl' => 'http://example.com'
];

echo $book['name'];

/* __________________________________________________
Update an Array
We've prepared an array of two books. Your job is to extend each item to include the book's release year. Use releaseYear for the key. Get to work!
*/

// "Do Androids Dream of Electric Sheep" was released in 1968.
// "Project Hail Mary" was released in 2021.

$books = [
	[
		'name' => 'Do Androids Dream of Electric Sheep',
		'author' => 'Philip K. Dick',
		'purchaseUrl' => 'http://example.com',
        'releaseYear' => 1968,
	],
	[
		'name' => 'Project Hail Mary',
		'author' => 'Andy Weir',
		'purchaseUrl' => 'http://example.com',
        'releaseYear' => 2021,
	]
];

@AdilAzhari

Copy link
Copy Markdown

<!doctype html>

<title>Demo</title> 'Do Androids Dream of Electric Sheep', 'author' => 'Philip K. Dick', 'purchaseUrl' => 'http://example.com', 'releaseYear' => 2020, ], [ 'name' => 'Project Hail Mary', 'author' => 'Andy Weir', 'purchaseUrl' => 'http://example.com', 'releaseYear' => 1992, ] ]; ?>
<ul>
    <?php foreach ($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
                <?= $book['name'] . " " . $book['releaseYear']?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

@djoooles

Copy link
Copy Markdown
<title>Arrays</title>

Recomended Books

<?php 

    $books = [
        [
            'name' => 'Do Andoroids Dream of Electric Sheep',
            'autor' => 'Philip K. Dick',
            'purchaseUrl' => 'http:/example.com'
        ],
        [
            'name' => 'Project Hail Marry',
            'autor' => 'Andy Weir',
            'purchaseUrl' => 'http:/example.com'
        ],
    ];
?>

<ul>
    <?php foreach($books as $book) : ?>
        <li>
            <a href="<?= $book['purchaseUrl'] ?>">
                <?= $book['name']; ?>
            </a>
        </li>
            
    <?php endforeach; ?>
</ul>

@yanji12-droid

Copy link
Copy Markdown
<style> body{ display: grid; place-items: center; font-size: 30px; padding-top: 200px; font-style: italic; } body ul{ background-color: grey;
}
</style>
'Babur-Nama', 'Author' => 'Babur', 'PurchaseUrl' => 'http://example.com', 'ReleaseYear' => 2005 ], [ 'name' => 'Bahay Kubo', 'Author' => 'Gian', 'PurchaseUrl' => 'https://genius.com/Jona-bahay-kubo-lyrics', 'ReleaseYear' => 2000 ]
];

?>

      <li>   <a href=<?= $book['PurchaseUrl'] ?> >
        <?= $book['name'] ?>
       </li>
    
    Release Date:
             <li>
                Author:
                <?= $book['Author'] ?>
             </li>
    

@nixsoftict

Copy link
Copy Markdown

$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