Php - multidimensional array using for or foreach

0

People, I need help, look at the examples below:

$cores = array (‘vermelhas’,’amarelas’,’verdes’)

$ frutas = array(
                         array (‘maçã’,’morango’,’cereja’,’acerola’),
                         array (‘banana’,’melão’),
                         array (‘abacate’,’kiwi’,’pera’))

I need to display the above arrays and then the multi-dimensional arrays in list format, they should be displayed as the example below, using for or foreach:

Vermelhas
• maça
• morango
• cereja
• acerola

Amarelas
• banana
• melão

Verdes
• abacate
• kiwi
• pera
    
asked by anonymous 06.08.2018 / 14:33

2 answers

0

Good morning, follow an example in Pastebin: link

Each index of the $ color array has a list of fruits, which will be displayed in list format .

In foreach of php, the format is as follows: foreach ($ list as $ index = > $ values)

In this way, the name of the core will be $ index , and the fruits will be in $ values , needing another foreach in $ values > to display each value in the fruit list.

    
06.08.2018 / 14:50
-1

Sorry, I reversed, the correct one is:

$cores =array (‘vermelhas’,’amarelas’,’verdes’)
    
06.08.2018 / 14:48