Reputation: 227
There has got to be a better way to write this:
<?php $imagecounter = "no";
foreach (glob("images/*.jpg") as $image) {
$imagecounter = "yes";
}
foreach (glob("images/*.png") as $image) {
$imagecounter = "yes";
}
foreach (glob("images/*.gif") as $image) {
$imagecounter = "yes";
}
if ($imagecounter == "yes"){Create gallery}?>
That folder might have zip or pdf files too that should not create a gallery
Upvotes: 2
Views: 2973
Reputation: 20
I think you want to remove foreach looping and check that in images folder any extension from "jpg,png,gif". so you can use ternary operator. Here is sample code.
$imagecounter = glob("img/*.jpg")?'yes':$imagecounter;
$imagecounter = glob("img/*.png")?'yes':$imagecounter;
$imagecounter = glob("img/*.gif")?'yes':$imagecounter;
if ($imagecounter == "yes"){Create gallery}
?> If i assume wrong, let me know mate.
Upvotes: -2
Reputation: 46900
if(glob("images/*.{jpg,png,gif}", GLOB_BRACE))
{
//create gallery
}
And that's about it :)
Upvotes: 10