PHP排序多维数组的内部多维数组与日期。

时间:2021-01-05 21:32:14

I have searched this site, looking for answers, but I cannot make it work. So finally I post this question knowing that there are a lot of possible duplicates. But when I try to use the answers, I get error messages of stdClass

我搜索了这个网站,寻找答案,但我不能让它工作。所以最后我提出这个问题,知道有很多可能的重复。但是当我尝试使用这些答案时,我得到了stdClass的错误消息。

I have an array with these values:

我有一个带这些值的数组:

Array
(
    [1251] => stdClass Object
        (
            [vid] => 1253
            [uid] => 20
            [body] => Array
                (
                )

            [field_datum] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 2016-09-17T11:30:00
                                    [timezone] => Europe/Brussels
                                    [timezone_db] => UTC
                                    [date_type] => date
                                )

                        )

                )
        )

I would have to sort this array with the value of the field_datum [field_datum][und][0][value]

我必须将这个数组与field_datum [field_datum][und][0][值]的值进行排序

I have tried this sollution: Sorting by key in a multidimensional array with php

我尝试过这种方法:用php对多维数组中的键进行排序。

But I get this as an error Fatal error: Cannot use object of type stdClass as array

但我将此作为一个错误致命错误:不能使用stdClass类型的对象作为数组。

1 个解决方案

#1


0  

With all the answers you gave, I found a solution

在你给出的所有答案中,我找到了一个解决方案。

function cmp($a, $b) {
  if ($a->field_datum == $b->field_datum) {
    return 0;
  } else {
    return $b->field_datum < $a->field_datum ? 1 : -1; 
  }
}

usort($infodagen, 'cmp');

#1


0  

With all the answers you gave, I found a solution

在你给出的所有答案中,我找到了一个解决方案。

function cmp($a, $b) {
  if ($a->field_datum == $b->field_datum) {
    return 0;
  } else {
    return $b->field_datum < $a->field_datum ? 1 : -1; 
  }
}

usort($infodagen, 'cmp');