-1

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

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]

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

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

Community
  • 1
  • 1
  • post code that causes an error. – mmmm Aug 26 '16 at 13:08
  • 1
    Error because you use a object and the solution use array. class->attribute, no class['attribute']. And the examble is very different that you case. – Maxi Schvindt Aug 26 '16 at 13:11
  • You need iterate to array and get value date and convert this value to timestamp and create new array[timestamp1][0]=>object, array[timestamp1][1]=>object, array[timestamp2][0]=>object.. and them sort array. – Maxi Schvindt Aug 26 '16 at 13:14

1 Answers1

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