I have the following code producing an array of filenames in a directory.
<?php
$filepathname= '../clients/Quote/'.date('ymd').'*';
$filesfound = array_map('basename', glob($filepathname));
print_r ($filesfound);
?>
This produces the Array ( [0] => 14060603.pdf [1] => 1406060301.pdf )
I want to remove the filename extension. .pdf. so that it instead produces the Array ( [0] => 14060603 [1] => 1406060301 )
Thank you for your help.
Furthermore as a second question how can I get the key in this array that has the highest value.
therefore [1] => 1406060301 would be selected.
If you know that the files all end with .pdf
, you may use the optional second parameter of 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
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.