Question:
What is the best PHP 7+ approach for sorting the following array
based on the array instance (string
) value of array->status
.
Goal:
Re-order the array
based on the status
value. If the value is "StatusAvailable
", I would want to move the array
instance to the top of the array
. Since the array
may contain multiple instances where a status of "StatusAvailable
" is defined, the next ordering condition fallback would be the date
value.
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
)