Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按时间排序数组中的数据_Php_Html_Arrays - Fatal编程技术网

Php 按时间排序数组中的数据

Php 按时间排序数组中的数据,php,html,arrays,Php,Html,Arrays,为什么我会收到一个错误,指出$image不是数组?我还希望能够对$image中的图片/文件进行排序。我想在上传时对它们进行排序。首先上传到我的页面的顶部。这两个问题一直困扰着我 $files = glob("Pictures/*.*"); for ($i=0; $i<count($files); $i++) { $image = $files[$i]; sort($image); $supported_file = array( 'gif',

为什么我会收到一个错误,指出$image不是数组?我还希望能够对$image中的图片/文件进行排序。我想在上传时对它们进行排序。首先上传到我的页面的顶部。这两个问题一直困扰着我

$files = glob("Pictures/*.*");
for ($i=0; $i<count($files); $i++)
{
    $image = $files[$i];
    sort($image);
    $supported_file = array(
        'gif',
        'jpg',
        'jpeg',
        'png'
        );

    $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
    if (in_array($ext, $supported_file)) {
        echo basename($image)."<br />"; 
        echo '<img src="'.$image .'" alt="Random image" height="150" />';
        echo '<div class="content_wrapp">
$files=glob(“Pictures/*.*);

对于($i=0;$i您应该对
$files
进行排序,而不是对
$image
进行排序。使用带有比较文件时间的函数的
usort

$files = glob("Pictures/*.*");
usort($files, function($a, $b) { return filemtime($b) - filemtime($a); });
及及