Foreach in fields

Asked

Viewed 66 times

0

Good afternoon. I’m having trouble showing the data of a form, where they can have multiple addresses and within those 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, will show only 2 involved and will not matter if it is from the first registration or the second .

Below is a screenshot of the form. inserir a descrição da imagem aqui

  • your code is correct? should not close the foreach??

  • no error of syntax friend

  • now no more :P

  • $input[endereco] will give syntax error, assuming that endereco is not an application constant.

  • i use Laravel and $input[field] is something I can use

  • How would it have to be? I couldn’t get it right.

  • You could give a print_r($input) to see how this array looks?

  • I ended up choosing to use the register in another way, because the way I was doing, it wasn’t going to work. When debugging the $input variable, it showed several arrays

Show 3 more comments

1 answer

0

If I understood the idea correctly, the logic in foreach is a little confused.

Admitting that in the variable $input you own several addresses, and within the addresses, several involved, I believe I’d look something like this:

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

This way would be displayed all the addresses and their respective involved (breaking in each line this par).

  • I tried to use so tbm, but when I put that in the address São Paulo has involved Luiz and Linhares, in the address Rio de Janeiro has involved Pedro and Anderson, by using the foreach he will return that in the address São Paulo has involved Luiz, Linhares, Peter and Anderson and Address São Paulo tbm would be showing the 4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.