Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $header = null;
- $pcs = array();
- if (($handle = fopen($filename, 'rb')) !== false) { // opening using rb is binary safe, not necessary just safer in this multi-byte emoji world
- while (($row = fgetcsv($handle)) !== false ) { // don't need to define the length of delimiter if you're just on the defaults
- // just a quick way to skip over the header row
- if (is_null($header)) {
- $header = $row;
- continue; // continue will skip the rest of the logic in this loop iteration, but not break out of the loop
- }
- list($ip, $side, $pos) = $row; // get the first three values from the $row array and assign them to variables
- // print_r($row);
- // $ip = $row[0];
- // $side = $row[1];
- // $pos = $row[2];
- if (empty($side)) { // empty checks for null, 0 or empty string values
- continue;
- }
- $pcs[$ip] = $ip; // and then assign them into an associative array, using the array key as the code and the value as the name
- $pcs[$pos] = $pos; // and then assign them into an associative array, using the array key as the code and the value as the name
- $pcs[$side] = $side;
- print_r($pcs);
- }
- fclose($handle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement