【发布时间】:2017-05-23 21:31:18
【问题描述】:
我正在开发一个带有肖像的图片库,我从 Exif 数据中提取文本。当我编辑图片时,我会写下人物的名字,这些名字稍后会在图片库中显示为标题。
我想创建一个列表,但不知道如何将其制成一个数组,我可以使用array_unique() 排除重复项。
我的代码是:
$imgdir = 'images/'; //pick your folder ie.: 'images/'
$current_folder = basename(dirname(__FILE__));
$allowed_types = array('png','jpg','jpeg','gif');
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg)){
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types)){
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img);
?><!DOCTYPE html>
<html>
<head>
<title>Names listing</title>
</head>
<body>
<?php
for ($x=0; $x < $totimg; $x++){
if ($x == ($totimg-1))
$_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).'';
else
$_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).', ';
$_unique = $_content;
echo $_unique;
}
?>
</body>
</html>
如果我有同一个人的多张图片,我会得到如下列表:
John, John, Jane, Jane, Jane, ... etc.
我想要的是:
John, Jane, ... etc.
提前致谢。
【问题讨论】:
标签: php arrays exif array-unique