I am trying to create a script that takes a $$variable and adds them to each other a number of times (based on another variable) – $total
This script is part of a much larger script that contains a few SQL queries and loops, hence the $$value as opposed to the usual $value
My current (static) script is like so:
$$value = ($$value + $$value + $$value + $$value + $$value);
This will work if I continue to modify the number of + $$value within the brackets but I need it to auto calculate and ammend itself so that it always writes the correct number of + $$value
I have tried using str_repeat() but it only fetches the first value of the $$value variable and then repeats that value (not grabbing the next value and so on). I have also tried creating a loop, which also didn’t work.
I need something that will look at $total and from that number produce something similar to the following:
$$value = ($$value * $total)
The above will multiply the numeric value of the $$value and therefore not return the result I want.
Can anyone help?
Many thanks,
Tom
Pastebin Link to my script: http://pastebin.com/7Qg02hWB (in the pastebin, $$value is $$ob_id and $total is $o_total)
Not 100% sure what you mean, but how’s
This will loop over $total times and concatenate it. If you’re having problems like it’s adding it as an integer for some reason you could always do a cast like
(string) $$value. I know you said you tried a loop but we have no code so it could have been a problem with your code.