title: Keep getting Undefiend Index when using json_decode
body: <p>I'm working with an API and I keep getting Undefined Index when trying to echo the data out,</p>
  <p>If I use this code:-</p>
  <pre><code>    &lt;?php
  $registration= $_GET['registration'];
  
  $curl = curl_init();
  
  curl_setopt_array($curl, array(
    CURLOPT_URL =&gt; &quot;https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests/?registration=$registration&quot;,
    CURLOPT_RETURNTRANSFER =&gt; true,
    CURLOPT_ENCODING =&gt; &quot;&quot;,
    CURLOPT_MAXREDIRS =&gt; 10,
    CURLOPT_TIMEOUT =&gt; 30,
    CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST =&gt; &quot;GET&quot;,
    CURLOPT_HTTPHEADER =&gt; array(
      &quot;cache-control: no-cache&quot;,
      &quot;content-type: application/json&quot;,
      &quot;x-api-key: mykey&quot;
    ),
  ));
  
  $response = curl_exec($curl);
  $err = curl_error($curl);
  
  curl_close($curl);
  
  
  echo $response;
  
  
  ?&gt;
  </code></pre>
  <p>I get this output:-</p>
  <pre><code>[{&quot;registration&quot;:&quot;myreg&quot;,&quot;make&quot;:&quot;TOYOTA&quot;,&quot;model&quot;:&quot;PRIUS&quot;,&quot;firstUsedDate&quot;:&quot;2014.10.26&quot;,&quot;fuelType&quot;:&quot;Hybrid Electric (Clean)&quot;,&quot;primaryColour&quot;:&quot;White&quot;,&quot;motTests&quot;:[{&quot;completedDate&quot;:&quot;2018.02.07 17:57:53&quot;,&quot;testResult&quot;:&quot;PASSED&quot;,&quot;expiryDate&quot;:&quot;2019.02.06&quot;,&quot;odometerValue&quot;:&quot;21645&quot;,&quot;odometerUnit&quot;:&quot;mi&quot;,&quot;motTestNumber&quot;:&quot;827555092722&quot;,&quot;rfrAndComments&quot;:[]}]}]
  </code></pre>
  <p>And then if I add this to the end of the code</p>
  <pre><code>$info=json_decode($response,true);
  echo $info['registration'];
       
  </code></pre>
  <p>I get a &quot;Notice: Undefined index: registration&quot;</p>
  <p>Looking at the docs for json_decode I cannot see what I am doing wrong.
  On another API I have used I noticed it was using
  CURLOPT_CUSTOMREQUEST =&gt; &quot;POST&quot;, and had this line underneath
  CURLOPT_POSTFIELDS =&gt; json_encode(['registration' =&gt; $registration]),</p>
  <p>And it would echo out.
  This one wont and the only difference I see is the GET</p>
  <p>So has it got something to do with the  CURLOPT_CUSTOMREQUEST =&gt; &quot;GET&quot;,
  line to why I cannot echo anything out?</p>
  <p>Thanks in advance for any help</p>