| 1 |
<?php |
| 2 |
|
| 3 |
namespace FakerPress; |
| 4 |
|
| 5 |
/** |
| 6 |
* Sorting function based on Priority |
| 7 |
* |
| 8 |
* @since 0.5.1 |
| 9 |
* |
| 10 |
* @param object|array $a First Subject to compare. |
| 11 |
* @param object|array $b Second subject to compare. |
| 12 |
* |
| 13 |
* @return int |
| 14 |
*/ |
| 15 |
function sort_by_priority( $a, $b ) { |
| 16 |
if ( is_array( $a ) ) { |
| 17 |
$a_priority = $a['priority']; |
| 18 |
} else { |
| 19 |
$a_priority = $a->priority; |
| 20 |
} |
| 21 |
|
| 22 |
if ( is_array( $b ) ) { |
| 23 |
$b_priority = $b['priority']; |
| 24 |
} else { |
| 25 |
$b_priority = $b->priority; |
| 26 |
} |
| 27 |
|
| 28 |
if ( (int) $a_priority === (int) $b_priority ) { |
| 29 |
return 0; |
| 30 |
} |
| 31 |
|
| 32 |
return (int) $a_priority < (int) $b_priority ? -1 : 1; |
| 33 |
} |
| 34 |
|