In PHP the equivalent for which you ask is this: .=
and it is called operator Concatenation mapping , which adds the argument from the right side to the argument on the left side. Of course, the variable must exist before using it, you must take care of that or your error log will be filled with PHP Notice: Undefined variable , although it will work the same, do not use the variable without first declaring it empty or with a desired initial value.
In the example that you put the code would be like this:
$numeros = array("uno ","dos ","tres ");
$numerosencadena = "";
foreach ($numeros as $valor) {
// Aquí necesito ir concatenando los valores en $numeroscadena
//para que queda algo así $numeroscadena = "uno dos tres "
$numerosencadena .=$valor;
}
echo $numerosencadena;
Exit:
uno dos tres
Another possibility
In the specific case of arrays you can use implode
which serves precisely for join elements of an array in a single string .
implode
receives two parameters: the first is the value that will be pasted at the end of each value of the array, and the second is the array itself.
In this case, a line of code would be enough to do what you want. Here you indicate that you want each value of the array separated by a blank space: " "
:
$conImplode = implode(" ", $numeros);
echo $conImplode;
Exit:
uno dos tres