You can concatenate the string as @rray put it in the comments:
$ids_ .= $id_inscrito .'|';
Remembering that you should initialize the variable $ids_
before the loop. Another point to consider is that the last id will always be followed by a character |
. A more complete solution would be like this:
$ids_ = '';
foreach (...) {
// codigo
// se o $ids_ não estiver vazio adiciona '|' antes do próximo id
$ids_ .= ($ids_ == '') ? $id_inscrito : '|' . $id_inscrito ;
}
Another possible way is to use arrays, as @Haroldotorres put in their answer:
$ids_ = array();
foreach (...) {
// codigo
$ids_[] = $id_inscrito;
}
$ids_ = implode('|', $ids_);
Use the operator
.=
to concatenate strings.– rray
Like the
for each
will vary? What changes from one element to the other? Where does its data source come from?– Maniero
Edit the question and add the code where the foreach is
– rray