I have a .txt file that looks like this:
Test = 10849831 = August 6, 2013:
56cake = 0 = August 6, 2013:
Wwe = 812986192 = August 6, 2013:
Test = 346192 = August 9, 2013:
Then, I use the following PHP code...
$Output = array();
$Lines = explode(":", $txt);
foreach($Lines as $line) {
$Rows = array_map('trim', explode(" = ", $line));
if(!isset($Rows[0], $Rows[1], $Rows[2])) continue;
$Output[$Rows[0]] = array($Rows[1], $Rows[2]);
}
print_r($Output);
...to turn the .txt file into a multidimensional array that looks like this:
Array
(
[Test] => Array
(
[0] => 346192
[1] => August 9, 2013
)
[56cake] => Array
(
[0] => 0
[1] => August 6, 2013
)
[Wwe] => Array
(
[0] => 812986192
[1] => August 6, 2013
)
)
However, there is a BIG error. The code removes all of the duplicate data values. In my example txt file, I had TWO values with the name "Test" however the code only outputs ONE in the multidimensional array.
You can also notice how the code replaced the data of the first "Test" element (in the multidimensional array) with the latest one (last line in the .txt file).
The data for the first "Test" element in the array DOES NOT even match the data in the first line of the .txt file Test = 10849831 = August 6, 2013:
.
How can I resolve this issue? I want the multidimensional array to look like this:
Array
(
[Test] => Array
(
[0] => 10849831
[1] => August 6, 2013
)
[56cake] => Array
(
[0] => 0
[1] => August 6, 2013
)
[Wwe] => Array
(
[0] => 812986192
[1] => August 6, 2013
)
[Test] => Array
(
[0] => 346192
[1] => August 9, 2013
)
)