PHP7 +基于数组实例值的排序和数组

时间:2018-10-26 14:23:30

标签: php arrays sorting stdclass

问题:

最好的 PHP 7 + 方法是根据array的数组实例(string)值对以下array->status进行排序的。

目标:

根据array值对status重新排序。如果值为“ StatusAvailable”,我想将array实例移到array的顶部。由于array 可能包含定义状态为“ StatusAvailable”的多个实例,因此下一个排序条件回退将是date值。

Array
(
   [0] => stdClass Object
       (
           [date]   => 1432875600000
           [value1] => TEXT
           [value2] => TEXT
           [value3] => TEXT
           [value4] => TEXT
           [value5] => TEXT
           [status] => 
           [value6] => TEXT
           [value7] =>
       )

    [1] => stdClass Object
       (
           [date]   => 1432875600000
           [value1] => TEXT
           [value2] => TEXT
           [value3] => TEXT
           [value4] => TEXT
           [value5] => TEXT
           [status] => StatusAvailable
           [value6] => TEXT
           [value7] =>
       )


    [2] => stdClass Object
       (
           [date]   => 14472543800000
           [value1] => TEXT
           [value2] => TEXT
           [value3] => TEXT
           [value4] => TEXT
           [value5] => TEXT
           [status] => SomeOtherStatus
           [value6] => TEXT
           [value7] =>
       )

    [3] => stdClass Object
       (
           [date]   => 1467349200000
           [value1] => TEXT
           [value2] => TEXT
           [value3] => TEXT
           [value4] => TEXT
           [value5] => TEXT
           [status] => StatusAvailable
           [value6] => NO
           [value7] =>
       )

    # the array list can/will continue at random length
)

0 个答案:

没有答案