title: PHP : Fetch the image using curl from JSON Format
body: <p>I want to fetch The Image from the JSON format using cURL PHP.<br>
  SO I Have created a code through which I am able to fetch the required Image.</p>
  
  <p>The JSON values are in this kind of Format : </p>
  
  <pre><code>[
  {
  "albumId": 1,
  "id": 1,
  "title": "accusamus beatae ad facilis cum similique qui sunt",
  "url": "https://via.placeholder.com/600/92c952",
  "thumbnailUrl": "https://via.placeholder.com/150/92c952"
  },
  {
  "albumId": 1,
  "id": 2,
  "title": "reprehenderit est deserunt velit ipsam",
  "url": "https://via.placeholder.com/600/771796",
  "thumbnailUrl": "https://via.placeholder.com/150/771796"
  },
  {
  "albumId": 1,
  "id": 3,
  "title": "officia porro iure quia iusto qui ipsa ut modi",
  "url": "https://via.placeholder.com/600/24f355",
  "thumbnailUrl": "https://via.placeholder.com/150/24f355"
  },
  ]
   ... and so on
  </code></pre>
  
  <p>The php Code I used is Shown Below.</p>
  
  <pre><code>$url = "https://jsonplaceholder.typicode.com/albums/1/photos";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($ch);
  
  curl_close($ch);
  $albumId = 1;
  $id = 3;
  $image_data = json_decode($result);
  foreach($image_data as $image) {
      if ($image - &gt; id == $id &amp;&amp; $image - &gt; albumId == $albumId) {
          echo "&lt;img src=".$image - &gt; url."&gt;";
          echo "&lt;br/&gt;";
          break;
      }
  }
  </code></pre>
  
  <p>I am getting the Result that I want but . is this the correct way to implement the code. or are there some loopholes in it. If there, please mention it.</p>
  
  <p>I need the Best Practice available for this Process.</p>