Is it possible to sort an array based on two parameters?

For ex, can the compare logic be written like this:

Sort based on the 1st parameter(has more preference), if this is not available then...