What are some common mistakes to avoid when implementing a PHP function to find a specific sum within an array of numbers?

One common mistake to avoid when implementing a PHP function to find a specific sum within an array of numbers is not properly checking for all possible combinations of numbers that add up to the target sum. To solve this, you can use a nested loop to iterate through the array and check all possible combinations.

function findSumInArray($arr, $targetSum) {
    $result = [];

    for ($i = 0; $i < count($arr); $i++) {
        for ($j = $i + 1; $j < count($arr); $j++) {
            if ($arr[$i] + $arr[$j] == $targetSum) {
                $result[] = [$arr[$i], $arr[$j]];
            }
        }
    }

    return $result;
}

// Example usage
$array = [2, 4, 6, 8, 10];
$target = 12;
$result = findSumInArray($array, $target);

print_r($result);