I got a project half-way through and I got this weird array which I now need to go through and store in a database.
The (weird) array $fields is like this:
array(10) {
["item_id"]=> string(1) "2"
["itemname"]=> array(3) {
[1]=> string(18) "Keyboard in en"
[2]=> string(21) "Keyboard in gr"
[3]=> string(20) "Keyboard in ru"
}
["shortDesc"]=> array(3) {
[1]=> string(0) "short_d en"
[2]=> string(0) "short_d gr"
[3]=> string(0) "short_d ru"
}
["description"]=> array(3) {
[1]=> string(7) "en test"
[2]=> string(7) "gr test"
[3]=> string(7) "ru test"
}
["item_code"]=> string(12) "PH31004PCS"
}
The table structure is like this:
id(AI) | language_id | item_code | item_name | short_description | description |
I need to automatically find the number of languages, (in the example is 3 but there could be more), and insert for each row the appropriate data.
Example: The row for English and Russian would be like this:
| id(AI) | language_id | item_code | item_name | short_description | description |
+--------+-------------+------------+----------------+--------------------+-------------+
| 1 | 1 | PH31004PCS | Keyboard in en | short_d en | en test |
| 2 | 3 | PH31004PCS | Keyboard in ru | short_d ru | ru test |
The problem: How should I navigate the array so I can store each row correctly and for all languages.
Failed attempts
However I tried to navigate the array all I managed to do was to get each inner array individually, all the names then all the short descriptions and then all the descriptions, instead of the first then second for each inner array and so on.