PHP排序函数在本地主机上的工作方式与在网站服务器上的工作方式不同

PHP排序函数在本地主机上的工作方式与在网站服务器上的工作方式不同,php,html,sorting,scandir,Php,Html,Sorting,Scandir,我有这个网站: 在底部,您可以看到产品图像。我所做的是将产品图像保存在文件夹中,并使用php scadir保存它们的名称。在每个名称的开头,我输入一个数字,以便对数组进行排序。例如,其中一个图像名称为1motor-oil.jpg。当我在localhost上使用sort函数时,它通常按数字进行排序,效果很好。在网站服务器上,虽然它根本不排序。 我不知道为什么。有人能帮我吗? 以下是我使用的代码: <?php //By Product Part $byProduct = "http:

我有这个网站:

在底部,您可以看到产品图像。我所做的是将产品图像保存在文件夹中,并使用php scadir保存它们的名称。在每个名称的开头,我输入一个数字,以便对数组进行排序。例如,其中一个图像名称为1motor-oil.jpg。当我在localhost上使用sort函数时,它通常按数字进行排序,效果很好。在网站服务器上,虽然它根本不排序。 我不知道为什么。有人能帮我吗? 以下是我使用的代码:

<?php
//By Product Part 
    $byProduct = "http://amsoil.com/shop/by-product/";
    $byEquipment = "http://www.amsoil.com/shop/by-equipment/";
    $dirEqui = "./assets/byEquipment";
    $dirPr = "./assets/byProduct";
    $imagesPr = scandir($dirPr,0);//save all the image names in alphabetical order(I used numbers for ordering in a way that I want)
    $imagesEqui = scandir($dirEqui,0);//save all product images in alphabetical order by equipment
    //i = 2 because the the first files in directory are . and ..
    sort($imagesEqui, SORT_NATURAL | SORT_FLAG_CASE);//sort by equipment
    sort($imagesPr, SORT_NATURAL | SORT_FLAG_CASE);//sort the array naturally
   for ($i=2; $i < count($imagesPr); $i++) { 
       if(preg_match('/\.(jpg|png)/',$imagesPr[$i])){
        //Delete .jpg from the file name
            $product = $imagesPr[$i];
            $product = preg_replace('/\.(jpg|png)/','',$product);
            $product = preg_replace('/\d+/','',$product);
        //Create links and pictures
            echo "<a href='".$byProduct.$product."?zo=".ZO."'><img class='products' src='".$dirPr."/".$imagesPr[$i]."'></a>";
       }else continue;
   }
?>

提前感谢大家的帮助。

您在本地机器和网站服务器上有什么PHP?SORT_NATURAL和SORT_FLAG_CASE参数仅适用于PHP5.4及以上版本。我怀疑您的网站服务器上可能有旧版本。运行phpinfo;为了知道你现在有哪个PHP版本。哦,我刚刚在网站服务器上运行了它,结果是我有5.3.13。非常感谢。这就是它不起作用的原因。有关排序参数的更多信息,请单击此处:http://php.net/manual/en/function.sort.php