I am working on creating div for each result coming from curl_exec json GET request. I have tried the code below using cURL in PHP. When I run this code nothing comes from the foreach.
//API Url
$url = 'https://api.clover.com:443/v3/merchants/'.$merchantid.'/categories/';
//Initiate cURL.
$ch = curl_init($url);
$headers = array(
'Content-type: application/json',
'Authorization: Bearer '.$authtoken.' ',
);
//Tell cURL that we want to send a GET request.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//Execute the request
$resp = curl_exec($ch);
$respArray = json_decode($resp, true);
foreach($respArray as $key => $value) {
echo $key . " : " . $value;
}
curl_close($ch);
This returns the following:
{
"elements": [
{
"id": "QWS8MSMAT49E6",
"name": "Other",
"sortOrder": 2
},
{
"id": "35K000MJVVFHE",
"name": "Pizza",
"sortOrder": 1
}
],
"href": "http://api.clover.com/v3/merchants/{[MID]}/categories?limit=100"
}
I'm trying to get the information above into a div, for example:

$respArrayin the foreach loop. But you should apply$respArray["elements"].PHP Warning: Invalid argument supplied for foreach(). When you say I should apply$respArray["elements"]what do you mean? where the change will be on my code? I am might missing the point of it. Thank you for your response.var_dump($respArray);? I mean change this lineforeach($respArray as $key => $value)toforeach($respArray["elements"] as $key => $value).int(1)fromvar_dump($respArray);int(1)back, where do you get the returning information from?