title: Php curl in foreach check status
body: <p>How to make a foreach or a loop when checking multidimensional array like ? What am i doing wrong ?</p>
  <p>I am trying to get status from BKM with vkn or tckn;</p>
  <p>Also i want to insert as 1 if merchant is blacklisted and as 0 if merchant is not blacklisted</p>
  <p>I have tried to find answer from a lot of forums but I couldnt get right answer if someone would help that would be great !</p>
  <pre><code>   $datas = [
        0 =&gt; [
          &quot;VKN&quot; =&gt; 23112131231,
          &quot;TCKN&quot; =&gt; 23232131313
             ],
        1 =&gt; [
          &quot;VKN&quot; =&gt; 232131232,
          &quot;TCKN&quot; =&gt; 231321412421
      ];
  </code></pre>
  <pre><code>    $insertData = [];
      $basic_auth = base64_encode(Merchant::BKM_USERNAME.':'.Merchant::BKM_PASSWORD);
  
      foreach ($datas as $key =&gt; $value)
      {
        $insertData[$key][&quot;user_id&quot;] = Auth::user()-&gt;id;
        $insertData[$key][&quot;vkn&quot;] = $value[&quot;VKN&quot;];
        $insertData[$key][&quot;tckn&quot;] = $value[&quot;TCKN&quot;];
  
        $ch[$key] = curl_init();
  
        curl_setopt($ch[$key], CURLOPT_URL, Merchant::BKM_TOKEN_URL);
        curl_setopt($ch[$key], CURLOPT_POST, true);
        curl_setopt($ch[$key], CURLOPT_POSTFIELDS, &quot;grant_type=password&quot;);
        curl_setopt($ch[$key], CURLOPT_HTTPHEADER, array('Accept: */*', 'Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic '.$basic_auth));
        curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
  
        $http_response[$key] = curl_exec($ch[$key]);
        $http_code[$key] = curl_getinfo($ch[$key], CURLINFO_HTTP_CODE);
        $http_error[$key] = curl_errno($ch[$key]) ? curl_error($ch[$key]) : '';
        curl_close($ch[$key]);
  
        if($http_code[$key] == 200)
        {
        $decoded[$key] = json_decode($http_response[$key], true);
        $token[$key] = $decoded[$key]['access_token'];
        $taxNo = $value[&quot;VKN&quot;] ? $value[&quot;VKN&quot;] : '';
        $identityNo = $value[&quot;TCKN&quot;] ? $value[&quot;TCKN&quot;] : $taxNo;
  
          if($taxNo) 
          {
           $get_param = '?TaxNo='.$taxNo;
          } else {
           $get_param = '?IdentityNo='.$identityNo;
          }
  
         $ch[$key] = curl_init();
         curl_setopt($ch[$key], CURLOPT_URL, Merchant::BKM_CHECK_URL.$get_param);
         curl_setopt($ch[$key], CURLOPT_HTTPHEADER, array('Accept: */*', 'Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic '.$basic_auth));
         curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
  
         $http_response2[$key] = curl_exec($ch[$key]);
         $http_code2[$key] = curl_getinfo($ch[$key], CURLINFO_HTTP_CODE);
         $http_error2[$key] = curl_errno($ch[$key]) ? curl_error($ch) : '';
         curl_close($ch[$key]);
         }
         if($http_code2[$key] == 200) {
                          $decoded2[$key] = json_decode($http_response2[$key], true);
      
                          echo json_encode($decoded2[$key], JSON_UNESCAPED_SLASHES);
                      } else {
                          echo json_encode($http_error2[$key], JSON_UNESCAPED_SLASHES);
                      }
                  } 
                  else {
                      echo json_encode($http_error[$key], JSON_UNESCAPED_SLASHES);
                      }
              }   
              
       if (isset($request-&gt;importAction) &amp;&amp; ($request-&gt;importAction == 'save_query')) {
                  $merchant_status-&gt;insert($datas);
              }
  </code></pre>