<?php

function csv_2_array($file) {
    if(
$data = @file_get_contents($file)) { // there was an error grabbing the data
        //echo $data;
        
        //split the data up by row
        
$spl_data explode("\n"$data);
        
//print_r($spl_data);
        
        //in a csv file, good practice indicates the first row of elements are the column names
        
$col_names $spl_data[0];
        
$col_names explode(', '$col_names);    
        
//print_r($col_names);
        
        
$col_cnt count($col_names);
        
        
//split the individual row data up, match it to the columns they belond to
        //first we have to unset $spl_data[0] (the column names)
        
$set_data array_shift($spl_data);
        
$spl_cnt count($spl_data);
        for(
$i=0$i<$spl_cnt$i++) {
            
$row_list[] = explode(','$spl_data[$i]);
        }
        
//print_r($row_list);
        
        //go through and do some sorting
        
$row_cnt count($row_list);
        
//go by each row
        
for($i=0$i<$row_cnt$i++) {
            
$temp_var $row_list[$i];
            
$temp_var_cnt count($temp_var);
            
//now go through. If the [0] is not empty, its the country (the [1] will be the country code).
            //we will want to throw these variables into the blank spaces.
            
if($temp_var[0] != "" && $temp_var[1] != "") { //the [0] has data (its a country) and [1] has data ([1] is the country code)
                
$now_country_name $temp_var[0];
                
$now_country_code $temp_var[1];
            }
            elseif(
$temp_var[0] == "" && $temp_var[1] == "") { //the country name and code are blank, we will want to fill them with the above values
                
$temp_var[0] = $now_country_name;
                
$temp_var[1] = $now_country_code;
            }
            
            
//now since we appended the array elements that count() == 2 to the empty-elements, we can get rid of the 2-count elements
            
if(count($temp_var) == 2) {
                unset(
$temp_var);
            }        
            
            if(
$temp_var != "") {
                
$toy_data[] = $temp_var;
            }
            
        }
        
        
//print_r($toy_data);
        
    
}
    else { 
//the data was retrieved
            
        
die('Failed to retrieve csv: ' .$file);
    }
    
    return 
$toy_data;
}

?>

<pre>

<?php

$file 
'test_csv.txt';
$parse_data csv_2_array($file);

print_r($parse_data);

?>

</pre>