Guest User

Untitled

a guest
Aug 16th, 2014
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // Set your CSV feed
  2. $feed = 'https://docs.google.com/spreadsheets/d/1Y6TNGpUkoCQzLtATw4LeIUFGTsZbXBx0mQAT_csKtyY/export?format=csv';
  3.  
  4. // Arrays we'll use later
  5. $keys = array();
  6. $newArray = array();
  7.  
  8. // Do it
  9. $data = csvToArray($feed, ',');
  10.  
  11. // Set number of elements (minus 1 because we shift off the first row)
  12. $count = count($data) - 1;
  13.  
  14. //Use first row for names
  15. $labels = array_shift($data);
  16.  
  17. foreach ($labels as $label) {
  18. $keys[] = $label;
  19. }
  20.  
  21. // Add Ids, just in case we want them later
  22. $keys[] = 'id';
  23.  
  24. for ($i = 0; $i < $count; $i++) {
  25. $data[$i][] = $i;
  26. }
  27.  
  28. // Bring it all together
  29. for ($j = 0; $j < $count; $j++) {
  30. $d = array_combine($keys, $data[$j]);
  31. $newArray[$j] = $d;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment