I have a file which looks like this:
Papiers peints > 3D et Perspective > 3D
Papiers peints > Carte du monde
Papiers peints > Fleurs
Papiers peints > Fleurs > Coquelicots
Tableaux > Cartes du monde
Tableaux > Fleurs
Tableaux > Fleurs > Coquelicots
and which I then transform into a properly formatted csv like this:
"Papiers peints","3D et Perspective","3D"
"Papiers peints","Carte du monde",
"Papiers peints","Fleurs",
"Papiers peints","Fleurs","Coquelicots"
"Tableaux","Cartes du monde",
"Tableaux","Fleurs",
"Tableaux","Fleurs","Coquelicots"
What I need is for each of these fields to have its own unique ID, which has to be an integer. This is how it should look like
"Papiers peints",101,"3D et Perspective",1001,"3D",10001
"Papiers peints",101,"Carte du monde",1002,,
"Papiers peints",101,"Fleurs",1003,,
"Papiers peints",101,"Fleurs",1003,"Coquelicots",10002
"Tableaux",102,"Cartes du monde",1004,,
"Tableaux",102,"Fleurs",1005,,
"Tableaux",102,"Fleurs",1005,"Coquelicots",10003
The names themselves don't matter at all and there will always be duplicates. I can solve this easily by uploading to a database. Then I do:
select distinct COL1
, give them their respective IDsselect COL2, group by COL1, COL2
, give them their respective IDsselect COL3, group by COL1, COL2,COL3
, give them their respective IDs- repeat for as many times as needed, which can be quite a lot
How do I do this in PHP without having to use a database? A straight answer would be nice, but even a design idea would help a lot.
There could be up to 10 columns in my file, but here is a simplified input array to work with:
$new=[0=>['a0','a1','a2','a3'],1=>['b0','b1','b2','b3'],2=>['c0','c1','c2','c3'],3=>['d0','d1','d2','d3'],4=>['e0','e1','e2','e3']];
Expected Result:
[
['a0','101','a1','1001','a2','10001','a3','100001'],
['b0','102','b1','1002','b2','10002','b3','100002'],
['c0','103','c1','1003','c2','10003','c3','100003'],
['d0','104','d1','1004','d2','10004','d3','100004'],
['e0','105','e1','1005','e2','10005','e3','100005']
]