I am trying to get first name and last name from a text file with while loop and store it in a global variable to which i want to access from any other function to echo all the first and last name in two different keys.
Here is my full code.
<?php
OutputNames();
function ReadNames()
{
$myFile = new SplFileObject("all/names.txt");
while (!$myFile->eof()) {
$row = str_getcsv($myFile->fgets());
$first = $row[0];
$last = $row[1];
}
}
function OutputNames()
{
echo $first." ".$last;
}
?>