problem setting up an array when reading a file


#1

I am trying to set up an array, but i’m not satisfied with the result. The problem is that i don’t quite understand how i can “remap” the array I want it to be. I would be glad if someone could help.

This is what i have:
Array
(
[0] => BTC
[1] => Bitcoin
[2] => 1
[3] => 2
[4] => 3
IOTA
[5] => Iota
[6] => 3
[7] => 2
[8] => 14
ETH
[9] => Ethereum
[10] => 7
[11] => -11
[12] => 14

LT C
[13] => Lite coin
[14] => 90011
[15] => 10
[16] => 11
XMR
[17] => Monero, the open-source CryptoNight currency
[18] => 1400
[19] => 14
[20] => 13
XRp
[21] => Ripple
[22] => 1
[23] => 1
[24] => 1

)

and this is how i want it to look:
Array
(
[BTC] => Array
(
[navn] => Bitcoin
[k1] => 1
[k2] => 11
[k3] => 17
)

[BAN] => Array
    (
        [name] => banana
        [k1] => 1000
        [k2] => 12
        [k3] => 27
    )

[PER] => Array
    (
        [name] => pear
        [k1] => 62
        [k2] => 13
        [k3] => 37
    )

[APL] => Array
    (
        [name] => apple
        [k1] => 51
        [k2] => 14
        [k3] => 47
    )

[ORG] => Array
    (
        [name] => orange
        [k1] => 31
        [k2] => 15
        [k3] => 57
    )

)

My code looks like this:

$read_file=file(“data.txt”);
foreach($read_file as $Read) {
trim($Read," “);
$felt =explode(”;",$Read);

}

echo “

”;
print_r ($felt);
echo “
”;

#2

Is the file contents the output of a print_r statement? If so, are you able to do something about the file format? It makes no sense and will be very painful to work with in contrast to working with ie a json file