<?php 

 $txtArray = fopen("doctors.txt", "r") or die("Unable to open file!");

 $hdrArray = explode("\t", $txtArray[0]); 

// array(3) { [0]=> string(5) "head1" [1]=> string(5) "head2" [2]=> string(6) "head3 " }



$length = count($txtArray) - 1; // having count in the for loop means it'll be executed at each iteration

$data   = array();



for($i = 1; $i <= $length; $i++) {

    $datArray = explode("\t", $txtArray[$i]); 

    // array(3) { [0]=> string(3) "v11" [1]=> string(3) "v12" [2]=> string(4) "v13 " }



    foreach($hdrArray as $key => $header) {

        $data[$i - 1][$header] = $datArray[$key]; // $i - 1 to start your $data array from 0

    }   

}

?>