I have this file that I would like to read into a multidimenstional array in php: file. If I take the first set of lines as a first example, I would like the print_r to look something like this:
Array
(
[SiiNunit] => Array
(
[0] => Array
(
[economy] => _nameless.2BB8.4FB8
[economy_data] => Array
[0] => Array
(
[bank] = _nameless.2917.43B0
[player] = _nameless.2813.6928
[companies] = 312
[companies[0]] = company.volatile.euroacres.nurnberg
[companies[1]] = company.volatile.euroacres.erfurt
etc...
Then as another example, further down the file when it is listing all of the jobs like this:
job_offer_data : _nameless.2BD0.8940 {
cargo: null
company_truck: ""
variant: nil
target: ""
expiration_time: nil
urgency: nil
shortest_distance_km: 0
ferry_time: 0
ferry_price: 0
trailer_pos: (0, 0, 0) (1; 0, 0, 0)
trailer_pos_valid: false
license_plate: ""
}
I would like the array to look somethink like this:
[job_offer] => _nameless.2BB8.4FB8
[job_offer_data] => Array
(
[0] => Array
(
[cargo] = null
[company_truck] = ""
[variant] = nill
[target] = ""
etc...
My code at the moment is:
<?php
// Open the file
$fp = @fopen("game.sii", 'r');
// Add each line to an array
if ($fp) {
$array = explode("\n", fread($fp, filesize("game.sii")));
}
print_r($array);
?>
this (as I expected it to) wrote each line of the file into a 1d array however, I would like it to write it to a multidimensional array=.
Even after lots of googling, I just cannot find the solution for how to do this (so I apologise if I have missed something obvious) so I was hoping someone on here could help me.
Thanks in advance, Marcus