That can be represented with a directed graph. When you have relative information about the height of two persons, add an edge between them such that it either points to the taller or shorter person. (Which does not matter as long as you're consistent.) To see if someone is shorter or taller than another, see if they are an ancestor or descendant of the other. If a cycle is formed, it means the information is inconsistent.
In PHP, you'd probably have a Person
class. Each Person
would have an array of Person
s that they're taller (shorter) than. You'd then have an array of Person
objects. To create a link, you'd add the tallest (shortest) person to the shortest (tallest) person's taller (shorter) arrays.
To test whether a person A is shorter (taller) than a person B, start with person A and recurse through all direct and transitive taller (shorter) persons. If you reach person B, person A is shorter (taller) than person B. Try swapping person A and B and seeing if that yields a result. If there is still no definite result, then there is not enough information to determine the relative heights of persons A and B.
In the case that the information is inconsistent, recursing as above will lead to infinite recursion.