I find your requirements to be poorly demonstrated by your sample data. There are no negative values and only one tie in the the qa column to break with sa. Perhaps you need to offer clearer sample data and your desired output.
I believe this is just a human-language difficulty. I will assume that by "negative" you mean "non-positive" (zero values).
The spaceship operator provides a far simpler technique for implementing multi-condition sorting.
Notice that there are no conditions in my sorting function's body. Arrays on either side of <=> are synchronously compared element-by-element.
By casting thechecking if qt values as booleansis larger than zero and using that boolean value, 0szeros become false and non-zeros become true. Furthermore when sorting booleans, false comes before true. By sorting $b <=> $a -- this is in DESC sorting. Ergoorder, trues come comes before falses.
Sort by qt DESCnon-zeros before zeros, then sa DESC: (DemoDemo)
usort(
$array,
function($a, $b) {
return [(bool)$b['qt'][$b['qt'] > 0, $b['sa']] <=> [(bool)$a['qt'][$a['qt'] > 0, $a['sa']];
}
);
Same thing from PHP7.4 and higher (DemoDemo)
usort($array, fn($a, $b) => [(bool)$b['qt'][$b['qt'] > 0, $b['sa']] <=> [(bool)$a['qt'][$a['qt'] > 0, $a['sa']]);