I have a loop like this below:
foreach ($header as $i) {
$i += $i;
}
I am trying to load a variable ($i) and then outside of that loop echo that variable like this below:
echo $i;
However it always returns 0;
Is it possible to get it to return the value that it created in the loop?
You can use implode()
to combine all the values.
$all = implode('', $header);
http://php.net/implode
$i
is re-assigned every time the loop iterates.
create a variable outside the loop, add to it during the loop, and echo again outside of it.
$outside_var = 0;
foreach ($header as $i) {
$outside_var += $i;
}
echo $outside_var;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With