user2807525
user2807525

Reputation: 3

Multidimensional array in txt file to php array

I'm developing a tool for a client, and I save the data in a txt file when using the tool offline, so that he can then upload this file onto server and save data in database.

The data in the text file are presented like below:

Array
(
    [idcategorie] => 1
    [idmasteruser] => 1
    [societe] => Company
    [marque] => Brand
    [audit] => AUdit
    [nom] => Baker
    [prenom] => James
    [phone] => 
    [email] => [email protected]
    [nboutils] => 3
    [outil0] => Array
        (
            [id] => 20
            [valeurs] => Array
                (
                    [0] => 24
                    [1] => 4
                    [2] => 27
                    [3] => 16
                )

            [file] => /newbam/images-up/HopbV_chefs.jpg
            [notes] => Array
                (
                    [0] => 4
                    [1] => 5
                    [2] => 7
                    [3] => 6
                )
           )
)

How can I put this data in a PHP array that I can handle after using keys?

Upvotes: 0

Views: 644

Answers (2)

Brian
Brian

Reputation: 7654

If you used var_dump to generate this data, restoring it back into an array is a non-trivial task. However, this is much easier if you export the data using var_export or serialize, which can be put back into an array.

Upvotes: 1

taiar
taiar

Reputation: 562

You can serialize the array:

http://php.net/serialize

It writes the array in a format that can be saved in a file and parsed later as an object or an array with unserialize:

http://php.net/unserialize

Hope it helps!

Upvotes: 0

Related Questions