Test this code online: https://onlinephp.io/c/e9a94
/**
 * @param Integer[] $nums
 * @param Integer $target
 * @return Integer[]
 */
function twoSum($nums, $target) {
	// calculate length of array - $nums
    $nums_len = count($nums);
    // iterate over $nums array
    for($i = 0; $i < $nums_len; $i++){
    	// find difference between $target and current number
        $diff = $target - $nums[$i];
        // remove that number and search index of current 
        // number in the $nums array
        unset($nums[$i]);
        $j = array_search($diff,$nums);
        // if there is an element return answer
        if($j != NULL){
            return [$i, $j];
        }
    }
}
by Vasil Grdzelishvili
2 years ago
PHP
leetcode
0
Pro tip: use ```triple backticks around text``` to write in code fences