需要从文件名array_map中删除.pdf扩展名


need to remove .pdf extension from filename array_map

我用下面的代码在一个目录中生成一个文件名数组。

<?php
$filepathname= '../clients/Quote/'.date('ymd').'*';
$filesfound = array_map('basename', glob($filepathname));
print_r ($filesfound);
?>

生成数组([0]=> 14060603.pdf [1] => 1406060301.pdf)

我想删除文件扩展名。pdf。所以它产生了Array ([0] => 14060603 [1] => 1406060301)

谢谢你的帮助。

作为第二个问题,我怎样才能得到这个数组中值最大的键

因此[1]=> 1406060301将被选择。

如果您知道所有文件都以.pdf结尾,您可以使用basename的第二个可选参数:

<?php
$filepathname= '../clients/Quote/'.date('ymd').'*';
$filesfound = glob($filepathname);
foreach($filesfound as $key => $val){
    $filesfound[$key] = basename($val, ".pdf");
}
print_r($filesfound);
$max = max(array_keys($filesfound));
print($max); // prints the key with the highest value
?>