Ad

Fixed your issue with finding

Code
Diff
  • function closestToZero(array $ints) {
      if(!empty($ints)){
        $closest = $ints[0];
      }else{
        return 0;
      }
      foreach($ints as $num){
        if(abs($num)< abs($closest)){
          $closest = $num;
        }
      }
      if($closest<0 && array_search(abs($closest), $ints)){
        return abs($closest);
      }else{
        return $closest;
      }
    }
    ?>
    • function closestToZero(array $ints) {
    • if(!empty($ints)){
    • $closest = $ints[0];
    • }else{
    • return 0;
    • }
    • foreach($ints as $num){
    • if(abs($num)< abs($closest)){
    • $closest = $num;
    • }
    • }
    • if($closest<0 && array_search(abs($closest), $ints)){
    • return abs($closest);
    • }else{
    • return $closest;
    • }
    • }
    • ?>