What are the best practices for sorting output in PHP based on specific conditions?

When sorting output in PHP based on specific conditions, you can use the `usort()` function along with a custom comparison function. This allows you to define the specific conditions for sorting the output.

// Example array to be sorted
$data = array(
    array('name' => 'John', 'age' => 30),
    array('name' => 'Jane', 'age' => 25),
    array('name' => 'Alice', 'age' => 35)
);

// Custom comparison function based on age
function sortByAge($a, $b) {
    return $a['age'] - $b['age'];
}

// Sorting the array based on age
usort($data, 'sortByAge');

// Output the sorted array
foreach ($data as $item) {
    echo $item['name'] . ' - ' . $item['age'] . "\n";
}