each line of The file $wordFile [which is over hundreds of lines],consists of a word + 'space' + decimal number + ' '.
I need to extract the number and word from the file and add them to the $indivFreq array. But am getting error
Notice: Undefined offset: 1 in /.....
This is my code:
$wordFile = file_get_contents("wordFile.txt");
$termArr = explode("
", $wordFile);
$wordFile2 = file_get_contents("wordFile2.txt");
$termArr2 = explode("
", $wordFile2);
$cityFreqsArr = array($termArr, $termArr2);
$twoTerms = array();
$decimalScore = number_format("0", 8);
$indivFreqs = array("", $decimalScore);
$twoDimFreqArr = [[]];
for($i=0; $i<count($termArr); $i++){
for($i2=0; $i2 < count($cityFreqsArr[$i]); $i2++){
$currentTerm = $cityFreqsArr[$i][$i2];
$currentTerm = trim($cityFreqsArr[$i][$i2]);
$twoTerms = explode(' ', $currentTerm); //separating each string of term and its frequency into the 2 parts
$indivFreqs[0] = $twoTerms[0];
$indivFreqs[1] = $twoTerms[1]; //**error is here
$twoDimFreqArr[$i][$i2] = $indivFreqs; //for each city and each term there is an array with the term and its frequency
//i.e.,
}
}
I tried printing out the contents of $twoTerms after the explode and am getting arrays with index 0 => word and index 1 => number, Which is why I don't understand why php won't see that it has an index of 1 also?