if ($current->left < $prev->right) { $depth++; } elseif ($current->left > ($prev->right + 1)) { $depth--; } // $depth stays the same