0
$images = valley_images();
var_dump($images);
$sorted_data = array();

foreach($images as $key => $value) {
    if ($key == 'timestamp') {
        $sorted_data[$value][] = $images;
    }
}

ksort($sorted_data);

错误出现在这一行:

$sorted_data[$value][] = $images;

当我对图像进行 var 转储时,我收到以下信息:

array(2) { 
[0]=> array(2) {
 ["id"]=> string(2) "17" ["timestamp"]=> string(10) "1359797773" 
} 
[1]=> array(2) {
 ["id"]=> string(2) "20" ["timestamp"]=> string(10) "1359934365"
} 
4

1 回答 1

1

一种对多维数组中的键进行排序的好方法,而无需先知道数组中有哪些键:

<?php 
$people = array( 
array("name"=>"Bob","age"=>8,"colour"=>"red"), 
array("name"=>"Greg","age"=>12,"colour"=>"blue"), 
array("name"=>"Andy","age"=>5,"colour"=>"purple")); 

var_dump($people); 

$sortArray = array(); 

foreach($people as $person){ 
    foreach($person as $key=>$value){ 
        if(!isset($sortArray[$key])){ 
            $sortArray[$key] = array(); 
        } 
        $sortArray[$key][] = $value; 
    } 
} 

$orderby = "name"; //change this to whatever key you want from the array 

array_multisort($sortArray[$orderby],SORT_DESC,$people); 

var_dump($people); 
于 2013-04-03T00:47:28.100 回答