fork(2) download
  1. <?php
  2. class Solution {
  3.  
  4. /**
  5.   * @param Integer[] $nums
  6.   * @param Integer $target
  7.   * @return Integer[]
  8.   */
  9. function twoSum($nums, $target) {
  10. foreach($nums as $key => $i ){
  11. $count = $i;
  12. foreach($nums as $key2 => $i2){
  13. if($i + $i2 == $target){
  14. return [$key , $key2];
  15. }
  16. $count = 0;
  17. }
  18. }
  19.  
  20. }
  21. }
  22. $f = new Solution;
  23. print_r($f->twoSum([2, 0, 6], 8));
  24.  
Success #stdin #stdout 0.02s 24384KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 0
    [1] => 2
)