Undefined array

Hello, im trying not show this error:

Warning : Undefined array key “status” in C:\xampp\htdocs\forge\index.php on line 163

but I’m kinda of lost, i call app and it returns status, the error appears when session has ended and i refresh page. Since there is no more status in $check variable. At least thats why I understand, im new at php.

Any ideas, or suggestions? Thanks.

$resp= curl_exec($curl);
curl_close($curl);
$json = json_decode($resp,true);
$check = $json['status'];

Do you know what Json formatting is? You used the “,true” option. Therefore you created an array called $json. In that you most likely have a multidimensional array. Json usually is an array of the top level such as "mydata ( “check” () )… Meaning that you have the top level name, is used Mydata as an example.
Therefore, you need to know what the name of the top level is and then access it something like this:
$check $json[“mydata-or-top-level”][“status”];

Now, to find out what it is, you can do something like this which will stop your code and show you what is inside the $json. You will then see the layout of the data. Hope this helps!

$json = json_decode($resp,true);
die("<pre>".print_r($json,1)."</pre>");
$check = $json['status'];

You will see what the array looks like and you will understand where STATUS is located.

1 Like

thanks a lot for your answer

Json is usually like XML. Just thought I would explain further. Loosely like:

<TopLevelName>
     <sublevelname1>
           SOME  DATA
    </sublevelname1>
     <sublevelname2>
           Some other data
    </sublevelname2>
</TopLevelName>

Then, with the decode and TRUE option, it is converted to an array. Loosely like:

$json = array(
    "TopLevelName" => array(
        "sublevelname1" => " Some data ",
         "sublevelname2" => "  Some  other data"
    )
);

Hope that explains it enough. Just an example, nothing working…

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service