Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. $header = null;
  2. $pcs = array();
  3. if (($handle = fopen($filename, 'rb')) !== false) { // opening using rb is binary safe, not necessary just safer in this multi-byte emoji world
  4. while (($row = fgetcsv($handle)) !== false ) { // don't need to define the length of delimiter if you're just on the defaults
  5. // just a quick way to skip over the header row
  6. if (is_null($header)) {
  7. $header = $row;
  8. continue; // continue will skip the rest of the logic in this loop iteration, but not break out of the loop
  9. }
  10. list($ip, $side, $pos) = $row; // get the first three values from the $row array and assign them to variables
  11. // print_r($row);
  12. // $ip = $row[0];
  13. // $side = $row[1];
  14. // $pos = $row[2];
  15. if (empty($side)) { // empty checks for null, 0 or empty string values
  16. continue;
  17. }
  18.  
  19. $pcs[$ip] = $ip; // and then assign them into an associative array, using the array key as the code and the value as the name
  20. $pcs[$pos] = $pos; // and then assign them into an associative array, using the array key as the code and the value as the name
  21. $pcs[$side] = $side;
  22.  
  23. print_r($pcs);
  24. }
  25.  
  26. fclose($handle);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement