title: Restart a PHP function with the value of the returned variable
body: <p>I'm working with proxies. For whatever reason, assuming a proxy fails, and I'm assuming this if 403 is returned; I would like to replace the proxy with another one (from an array). I'm unsure of how to implement it in. <strong>Assume there is an array of proxies at the top of the function called proxies</strong></p>
  
  <pre><code>public static function get_http_response_code($url, &amp;$redirect = null, $proxy = '23.244.68.94:80') {
      if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&amp;@#\/%?=~_|!:,.;]*[-a-z0-9+&amp;@#\/%=~_|]/i", $url)) return false;
  
      if (!is_null($proxy)){
  
          $useragent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36";
          $ch = curl_init();
  
          curl_setopt($ch, CURLOPT_PROXY, $proxy);
          curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_VERBOSE, 1);
          curl_setopt($ch, CURLOPT_HEADER, 1);
          $header = curl_exec($ch); 
          curl_close($ch);
      } 
  
      // Pattern to find the status code
      $codepattern = '/[0-9]{3}/';
      preg_match($codepattern, $header, $codematch);
  
      // Pattern to find the redirect link
      $linkpattern = '/https?:\/\/(.+)\//';
      preg_match($linkpattern, $header, $linkmatch);
  
      // Store results in an array
      $statuscode = (array_values($codematch)[0]);
      // Store the redirect link in the $redirect variable
      if ($statuscode == 301 || $statuscode == 302 || $statuscode == 303) {
          if (strpos(array_values($linkmatch)[0], 'http') !== false) {
              $redirect   = array_values($linkmatch)[0];
          } else {
  
          }
      } 
  
      return $statuscode;  
  }
  </code></pre>
  
  <p><code>$statuscode</code> would be returning the code. If it is 403, I would like to get the next proxy from the array and restart the function. I was thinking of doing <code>$proxy = next($proxies);</code> but just unsure where to add this </p>