Reputation: 137
I am trying to remove or hide match file names from array and i also removed file extension but how to hide/remove duplicate file name if match?
If output 'demo1','demo1','demo2',
then i want to do like this 'demo1','demo2',
Upvotes: 1
Views: 124
Reputation: 9270
Use the array_unique function, which does exactly that: it removes duplicates.
<?php
$images = array();
foreach (glob('{*.jpg,*.png}', GLOB_BRACE) as $key=>$image) {
$images[] = substr($image, 0, -4);
}
$images = array_unique($images);
foreach ($images as $key=>$image) {
if ($key == 0)
{ echo "'".substr($image, 0, -4)."'"; }
else
{ echo ",'".substr($image, 0, -4)."'"; }
}
?>
Upvotes: 2