Skip to content

Instantly share code, notes, and snippets.

@thinkverse
Last active June 8, 2021 02:59
Show Gist options
  • Save thinkverse/36c7276c289b962bb83f4c8fc5e369b0 to your computer and use it in GitHub Desktop.
Save thinkverse/36c7276c289b962bb83f4c8fc5e369b0 to your computer and use it in GitHub Desktop.
Single-line images gallery with `array_*` functions and `scandir`.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gallery</title>
<link rel="stylesheet" href="css/gallery.css">
</head>
<body>
<main>
<?php array_map(fn ($image) => printf('<img src="images/%s" alt="image" width="200" height="200">', $image), array_filter(scandir(realpath(__DIR__ . '/images')), fn ($file) => match (pathinfo($file, PATHINFO_EXTENSION)) { 'jpg', 'jpeg', 'png', 'gif', 'webp' => true, default => false, })); ?>
</main>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment