Yes, this ordering is only for display.
The way capabilities are done in code is to check for a specific capability directly, not for the role. In fact, checking for roles in code is poor practice: https://docs.moodle.org/dev/Access_API#Determining_that_a_user_has_a_given_capability.
In case of permission conflicts on the same capability in the same context inherited from multiple roles, there is a numerical weighting system to calculate the correct permissions when capabilities conflict. There's documentation on it somewhere I can't find at the moment, but this "tie-breaker" system is based on capabilities/permissions not on the role.
The way capabilities are done in code is to check for a specific capability directly, not for the role. In fact, checking for roles in code is poor practice: https://docs.moodle.org/dev/Access_API#Determining_that_a_user_has_a_given_capability.
In case of permission conflicts on the same capability in the same context inherited from multiple roles, there is a numerical weighting system to calculate the correct permissions when capabilities conflict. There's documentation on it somewhere I can't find at the moment, but this "tie-breaker" system is based on capabilities/permissions not on the role.