title: PHP Script to extract only bundle products from a json file and put them to another file
body: <p>I am new to PHP and I am trying to get specific data from a json file. Here is the file:</p>
  
  <pre><code>{
      "24-WG085": {
          "sku": "24-WG085",
          "product_type": "simple",
          "name": "Sprite Yoga Strap 6 foot",
          "price": 2.25
      },
      "24-WG085-dynamic": {
          "sku": "24-WG085-dynamic",
          "product_type": "simple",
          "name": "Sprite Yoga Strap Dynamic",
          "price": 10.45
      },
      "24-WG086": {
          "sku": "24-WG086",
          "product_type": "simple",
          "name": "Sprite Yoga Strap 8 foot",
          "price": 5.3
      },
      "24-WG087": {
          "sku": "24-WG087",
          "product_type": "simple",
          "name": "Sprite Yoga Strap 10 foot",
          "price": 8.35
      },
      "24-WG085_Group": {
          "sku": "24-WG085_Group",
          "product_type": "bundle",
          "name": "Set of Sprite Yoga Straps",
          "price": 11.4
      },
      "24-WG085-bundle-dynamic": {
          "sku": "24-WG085-bundle-dynamic",
          "product_type": "bundle",
          "name": "Sprite Yoga Strap Dynamic Bundle",
          "price": 14.45
      },
      "24-WG085-bundle-fixed": {
          "sku": "24-WG085-bundle-fixed",
          "product_type": "simple",
          "name": "Sprite Yoga Strap Fixed Bundle",
          "price": 17.5
      }
  }
  </code></pre>
  
  <p>So the idea if the product type is a ,,bundle" to get the key- for example: Sprite Yoga Strap Dynamic Bundle. Here is my code so far:</p>
  
  <pre><code>  &lt;?php
    $data = file_get_contents ("php-files-task.json");
      $json = json_decode($data, true);
      foreach ($json as $key =&gt; $value) {
          if (!is_array($value)) {
              echo $key . '=&gt;' . $value . '&lt;br/&gt;';
          } else {
              foreach ($value as $key =&gt; $val) {
                  echo $key . '=&gt;' . $val . '&lt;br/&gt;';
              }
          }
      }
      $fp = fopen('results.json', 'w');
  
  foreach ($value as $value) {
  fputcsv($fp, $value);
  }
  
  fclose($fp);
   ?&gt;
  </code></pre>
  
  <p>After I get all bundle products I want to put them in a new file- ,,results.json". I will appreciate any help. Thanks!</p>