$target) { // the sum is greater than the target, so we need to decrease the sum // to decrease the sum we will move our $right pointer to the left $right--; } else if ($list[$left] + $list[$right] == $target) { // if it's true, we have found a pair $ans++; // now we will move one of our pointers, otherwise it'll run forever $left++; # doesn't matter which one we move } // The loop will go until the pointers point to the same element } return $ans; # returning the number of pairs }