0
Hello, I need to assign several array to a single variable, their value will all be in sequence in this variable. Ex.:
$variavel = $array[0] . $array[1] . $array[2] . $array[3] . $array[4];
echo $variavel
This variable uses it later in an IF to make several comparisons, as I can do this without having to write infinitely assigned array?
It worked! Is there any way to generate these array? For example, generate array1, array2, array3 and so on... I know from
for
but when I try with it, I can’t get the variable that receives the array, outside the scope– user65739
@Sulivansantos I don’t understand the question. Generate in what way? What do you want to "create"?
– Gabriel Heming
I will try to explain, each position of the array stores information coming from the database, in the logic I am using here I take the variable that receives the concatenation of all the positions of the array, however for this, I need to express all the positions of the array manually in the code, wanted a way to simplify this, so that if you have for example 50 positions, I do not need to write 50 times, for example:
$variavel = $array[0] . $array[1] . $array[2] ... $array[49] . $array[50];
– user65739
@Sulivansantos utilize foreach.
foreach($array as $var) { echo $var; }
. Run this code and see how it works.– Gabriel Heming