I want to be able to extract each network plan with prices from this GET API. Can someone please help me out?
I want to Extract AIRTEL DATA PLAN [dataPlan, duration,type, status, and Price for basic_user] into a select Option format.
I have done this
$url = "https://subandgain.com/api/databundles.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
$obj = json_decode($response,true);
$suppliers = array();
$customers = array();
//echo "<pre>";
//print_r($obj);
foreach ($obj as $rkey => $resource){
if ($resource['NETWORK'] == 'AIRTEL'){
$customers[] = $resource;
} else if ($resource['NETWORK'] == 'MTN') {
$suppliers[] = $resource;
}
}
header('Content-Type: application/json');
$dataplan = json_encode($customers);
$objs = json_decode($dataplan,true);
echo "<pre>";
print_r($objs);
Please Help me out
2
Answers
The $objs variable is returning json_decode. Replace with json_encode. So I made adjustments and PHP got this format.
Assuming that the file where the code above is called api-plans.php, in the front file, I used the following code
Hope this helps
Try this!