我的目录中有这样的东西:
slider-1.jpg
slider-2.png
slider-4.gif
slider-8.png
slider-11.gif
现在有没有办法获得最后一个尾随数量的“滑块”图像?我需要得到这个,所以下一个上传的图像应该命名为slider-12.xxx
我尝试了每个循环,但它显然让我将滑块 3 作为下一个名称,在我的情况下这是错误的 :)
好的,这就是我的做法
foreach ($files as $filename) {
$filesarr[]= $filename;
$namearr = explode('.', $filename); //I had to grab this piece as well during the project, so this is main reason not usin Louis proposal.... i needed that array for something else...
$numbers = explode('-', $namearr[1]);
$compare[]=$numbers[2];
}
sort($compare, SORT_NUMERIC);
$assigned_number = end($compare) + 1;