vendredi 31 juillet 2015

PHP from string to multiple arrays at the hand of placeholders

Good day,

I have an I think rather odd question and I also do not really know how to ask this question.

I want to create a string variable that looks like this:

[car]Ford[/car]
[car]Dodge[/car]
[car]Chevrolet[/car]
[car]Corvette[/car]
[motorcycle]Yamaha[/motorcycle]
[motorcycle]Ducati[/motorcycle]
[motorcycle]Gilera[/motorcycle]
[motorcycle]Kawasaki[/motorcycle]

This should be processed and look like:

$variable = array(
                   'car'            =>           array(
                                                        'Ford',
                                                        'Dodge',
                                                        'Chevrolet',
                                                        'Corvette'
                                                      ),
                   'motorcycle'     =>           array(
                                                        'Yamaha',
                                                        'Ducati',
                                                        'Gilera',
                                                        'Kawasaki'
                                                      )
                  );

Does anyone know how to do this? And what is it called what I am trying to do?

Aucun commentaire:

Enregistrer un commentaire