title: How can I get this PHP for loop to run even if an error occurs?
body: <p>I'm aiming to get the second if statement to run if the $decode['results'][$i]['components']['ISO_3166-1_alpha-2'] throws a undefined array key error so that the 'country_code' one can be used instead.</p>
  <p>I'm trying with PHP try, catch but I can't seem to get it to work correctly. I don't know if I'm mis-using it's purpose or simply not doing it correctly.</p>
  <pre><code>for ($i = 0; $i &lt; count($decode['results']); $i++){
      try{
          if ($decode['results'][$i]['components']['ISO_3166-1_alpha-2'] === $_REQUEST['isoCode']){
              // echo json_encode($decode['results'][$i]['components']['ISO_3166-1_alpha-2']);
              //sends status data and api associative array to script.js
              $output['status']['code'] = &quot;200&quot;;
              $output['status']['name'] = &quot;ok&quot;;
              $output['status']['description'] = &quot;success&quot;;
              $output['status']['returnedIn'] = intval((microtime(true) - $executionStartTime) * 1000) . &quot; ms&quot;;
              $output['data'] = $decode['results'][$i];
  
              header('Content-Type: application/json; charset=UTF-8');  
                               
          }
      } catch (Exception $e) {
          if ($decode['results'][$i]['components']['country_code'] === $_REQUEST['isoCode']){
              // echo json_encode($decode['results'][$i]['components']['ISO_3166-1_alpha-2']);
              //sends status data and api associative array to script.js
              $output['status']['code'] = &quot;200&quot;;
              $output['status']['name'] = &quot;ok&quot;;
              $output['status']['description'] = &quot;success&quot;;
              $output['status']['returnedIn'] = intval((microtime(true) - $executionStartTime) * 1000) . &quot; ms&quot;;
              $output['data'] = $decode['results'][$i];
      
              header('Content-Type: application/json; charset=UTF-8');
          }     
      }
  }
  </code></pre>