$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"
}

最佳答案

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

<?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);

关于php - 胶印类型非法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15776864/

10-11 10:58