Foreach in fields

0

Good afternoon. I am having trouble displaying the data in a form, where it can have multiple addresses and within these addresses can have several involved. I tried something like:

foreach($input[endereco] as $key => $endereco){
    foreach($input[envolvidos] as $envolvidos){
       echo $endereco.' - '$envolvidos[$key].'<br>';
    }
}

But so, if you have 2 addresses, it will only show 2 involved and it will not matter if it is the first one or the second.

Below is an image of the form.

    
asked by anonymous 03.04.2018 / 21:09

1 answer

0

If I understood the idea well, the logic in foreach is a bit confusing.

Assuming that in the variable $input you have several addresses , and within the addresses, several involved , I think it would look something like this:

foreach($input[enderecos] as $endereco){
    foreach($endereco[envolvidos] as $envolvido){
       echo $endereco.' - '$envolvido.'<br>';
    }
}

In this way, all addresses and their respective parties will be displayed (by breaking each pair ).

    
03.04.2018 / 21:22