【发布时间】:2019-04-05 12:09:26
【问题描述】:
我已经用数据库中的数据填充了这个数组
$collectTable1 = array( 'errand' => $interest->errand_id,
'timestamp' => $interest->timestamp,
'type' => $interest->type,
'amount' => $interest->amount
);
$collector[] = $collectTable1;
我想重新排序时间戳,像这样
$sortTime = rsort($collectedData['timestamp']);
我试过了,我得到了这个输出
函数时间排序($a,$b){ 返回 (intval($a['timestamp']) > intval($b['timestamp'])); } usort($collector, "timesort");2017-12-01 10:53:26
我认为我会从降序日期点得到?就像是 2018-09-04 12:32:16。
我的时间戳还包含这样的 unixtimestamp 和常规日期“ 2017-12-01 10:53:26"
【问题讨论】:
-
使用
rsort($collectedData)因为$collectedData['timestamp']是单个值而不是数组,而不是$collectedData是一个数组 -
不知道,
$collectedData是什么?会不会是$collector的错字 -
您可以使用
is_array查看-secure.php.net/manual/en/function.is-array.php -
我想你可能的意思是你想按时间戳对数组进行排序,而不是像你试图做的那样......对时间戳进行排序
-
可能您只保留了数据库中的一行数据,这看起来像是一个更大问题的症状。
I have this array filled with data from a database当您获取数据时使用fetchAll或确保在“通常”一个 while 循环中使用$collectTable1[] = $row添加它或者仅使用 SQL 查询本身对数据进行排序(这不会解决“可能的”获取问题)