return 1;
in your first if there makes no sense – returning 1 means, $a is supposed to be considered greater than $b. So whenever either one of them is missing that value, you always say the first one should be considered the greater one.
The return value of the callback function only decides, whether $a should be considered less, equal or greater than $b. So if $a is missing the property, but $b has it – then you need to return -1, to make $a come before $b in the final result. If $a has it, and $b doesn’t – then you need to return 1. And if the both have it or are both missing it – then you need to continue comparing them, by your secondary comparison criterion.
solved PHP usort item missing keys to top [duplicate]