title: PHP script to convert Json to CSV
body: <p>I've got a API JSON service and need to create a script to export data to CSV files. 
  Does anyone have a php script to migrate JSON to CSV format?</p>
  
  <p>Example Json file</p>
  
  <pre><code>  {"packWidth":200,
    "itemNo":"SEH404",
    "groupItemNo":"SEH404",
    "status":1,
    "categoryId":24356,
    "packType":"ColorBox",
    "barcode":"1234567890987",
    "modelLabel":"Color",
    "modelList":[{"key":"SEH404","value":"Black"},{"key":"SEH404W","value":"White"}],
    "packQty":20,
    "packInclude":"USB Adapter, USB Charger, Earphone, Leather Case",
    "id":3456}
  </code></pre>
  
  <p>An important part is the array with the tag "modelList"</p>
  
  <p>The result of the array modelList, must be a column for each value</p>
  
  <p>example:</p>
  
  <p>packWidth, itemNo, groupItemNo, status, categoryId, packType, barcode, modelLabel, modelList1, modelList2, packQty, packInclude, id</p>
  
  <p>200, SEH404, SEH404, 1, 24356, ColorBox, 1234567890987, Color, <strong>SEH404:Black, SEH404W:White</strong>, 20, USB Adapter... , 3456</p>
  
  <p>Some products may also contain 5 records "modelList1-modelList2 modelList3-modelList4-modelList5. Products without modelList will record modelList empty.</p>