I have an array with 4 values I am running throgh in a foreach loop. Each iteration of this has another array with the same values which also runs in a loop.
The code I am having trouble writing is this:
run through array
run through second array in nested loop
check if nested array value is == to parent array value
if nested array value is < parent, what is the difference. Get diff and multiply by -520
if nested array value is == parent, keep same value
if nested array value is > parent, what is the differnce in values. get diff and multiply by 520
here is some code I have…can’t solve it at the moment though. hopefully someone can help:
Why would you want to match all values with all values? Shouldn’t it be
one value of the 2nd array with one from the first? Your code right will do 4
actions for 1 number 4 times.
Yeah, I need it to go through each number and then run another loop inside this for each number.
If the number of values is 5, run 5 times and within each iteration, run a sub-loop 5 times that checks the current value of the sub-loop against the value of the parent loop. If the sub-loop value is less than the parent loops, multiply the sub-loops position * -520. If the sub-loop value is greater than the parent loop, multiply it by the position away from the parent loop value * 520. ie:
code runs 1st and parent loop is at [1] on first iteration
subloop runs
second loop is at [1][1] so value [1] (parent) == [1] (subloop)
second loop is at 12 so value is 1 place above the parent loop…so 1 * 520
second loop is at [1][3] so value is now 2 places above the parent loop…so 2 * 520
second loop is at [1][4] so value is now 3 places above the parent loop, so 3 * 520
sub loop has run 4 times so finished and flow moves back to parent loop, which now iterates again which leads to;
code runs 2nd time and parent loop is at [2] on second iteration
subloop runs
second loop is at [2][1] so value [2] (parent) < [1] (subloop). The distance of the subloop position away from the parent loop position is 1. As it is subloop position < parent we mutliply * -520
Hope I have explained this well enough! It may seem like a strange setup but this is the logic I need for my application which will be a flat HTML code generator for something I am making that cant use PHP or anything like that.