Advertisement
GWibisono

kasi kayak gini aja.

Jan 31st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?PHP
  2. function readCSV($csvFile){
  3.     $file_handle = fopen($csvFile, 'r');
  4.     while (!feof($file_handle) ) {
  5.         $line_of_text[] = fgetcsv($file_handle, 20000);
  6.     }
  7.     fclose($file_handle);
  8.     return $line_of_text;
  9. }
  10.  
  11.  
  12. // Set path to CSV file
  13. $csvFile = 'test.csv';
  14.  
  15. $csv = readCSV($csvFile);
  16. echo '<pre>';
  17. print_r($csv);
  18. echo '</pre>';
  19.  
  20. //sortinng by pos ke 1
  21. $pos=1; //dimulai dari 0 tp saya milih 1
  22. $data=array();
  23. foreach($csv as $id=>$arr){
  24.    $id2=sprintf("%09s",$id);
  25.    $data[ $arr[$pos].$id2 ] = $arr;
  26. }
  27. ksort($data);
  28. echo '<pre>'.print_r($data,1).'</pre>';
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement