Firstly, this question explains how you read a file line by line in PHP. The top and bottom of it is:
$handle = fopen("inputfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
}
} else {
// error opening the file.
}
fclose($handle);
Now in your case, you've got a structured line. Namely.
<name><space><value>
I would strongly, strongly argue against using a multi dimensional array for this. Instead, go for an OOP based solution. First, define a class.
class Person {
protected $name;
protected $code;
function __construct($line) {
// Split and load.
}
}
Then you can create an array of Person
objects.
$people = array();
Then cycle through each line and create a Person
object.
while(($line = fgets($handle)) !== false) {
$people[] = new Person($line);
}
Now you've got all the pieces of the puzzle, it's up to you to put them all together!