Flanking

When you and an ally are flanking a foe, it has a harder time defending against you. A creature is off-guard (taking a –2 circumstance penalty to AC) to melee attacks from creatures that are flanking it.
To flank a foe, you and your ally must be on opposite sides of the creature. A line drawn between the center of your space and the center of your ally's space must pass through opposite sides or opposite corners of the foe's space. Additionally, both you and the ally have to be able to act, you must be wielding melee weapons or be able to make an unarmed attack, you can't be under any effects that prevent you from attacking, and you must both have the enemy within reach. If you're wielding a reach weapon, you use your reach with that weapon for this purpose.

3D Flanking

Though battle grids are often two-dimensional, the game world isn't! Sometimes you might need to visualize a creature's space as a cube for flanking. For instance, if Dae is positioned underneath a flying cloud ray while Navasi is flying above the cloud ray using her ultralight wings, they might be flanking it even if they're piled in an odd stack on your battle grid. And if Dae were riding an enercycle, they might be able to measure from farther off the ground than normal.
In these cases, it's usually best to have the GM make the call on who's flanking rather than trying to do meticulous measurements in three dimensions.