Please follow alone, I will explain a simple loop issue.
for($k=1;$k <10; $k++){
$test= $k;
echo $test; /// 123456789
}
echo $test; //// 9
as you can see, when I echo $test outside the loop, the results is 9. HOw can one echo $test outside the loop with all $k's values..
example.
for($k=1;$k <10; $k++){
$test= $k;
}
echo $test; //// 123456789
Update like this
$test[] = $k;
then use a foreach to retrieve the values.
Foreach($test as $value){
echo $value;
}
try using .= string operator
$test = "";
for($k=1;$k <10; $k++){
$test .= $k;
}
You need to string them together.
$test = "";
for($k=1;$k <10; $k++){
$test .= $k;
}
echo $test; //// 123456789
Period (.
) is use for concatenation in PHP.
for($k=1;$k <10; $k++){
$test .= $k;
}
echo $test;
The simple solution would be
$test = "";
for($k=1;$k <10; $k++){
$test.=$k;
}
echo $test; //// 123456789
That is, make test into a string and add the number at the end for every iteration. When the loop is done, print the string.
YOu cannot access $test outside the loop. The scope is local besides, the value of $test changes with every loop
What you want to do is: Store it in an string declared outside the loop to concat every time
$test="";
for($k=1;$k <10; $k++){
$test= $test.$k;
}
echo $test; //// 1235567890 Having said that, I dun think you should be doing this. If you post what exactly you are trying to do, we could help you