Here we will learn basic of Curl in PHP how Curl is working, We will get a code example of Api. Loop through JSON in PHP.

In this Video you will learn
1. Basic Curl Structore.
2. Get Data From Api.
3. Convert JSON to object.
4. Loop Through Object / array.

Code
<?php 

  $curl = curl_init();
  curl_setopt_array($curl, array(
 	  CURLOPT_URL => "https://jsonplaceholder.typicode.com/todos",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "GET"

  ));
  $response = curl_exec($curl);
  $data = json_decode($response);

  foreach ($data as $key => $value) {

    echo $value->userId;
    echo '<br>';
    echo $value->id;
    echo '<br>';
    echo $value->title;
    echo "<br><br>";
  }


  curl_close($curl);
?>

Thanks

By Soronix

Leave a Reply

Your email address will not be published. Required fields are marked *