Good afternoon,
I am trying to compare in a foreach loop a data with the previous iteration, but I am not able to access this iteration, is there any way?
I need to sort a list, but if there are two equal values they have the same order, with the array{ name:"aaaaa", valor:2 name:"bbbbb", valor:10 name:"ccccc", valor:10 name:"ddddd", valor:10 name:"eeeee", valor:45}get as a result{ name:"aaaaa", pos:1 name:"bbbbb", pos:2 name:"ccccc", pos:2 name:"ddddd", pos:2 name:"eeeee", pos:3}I am trying to save the pos outside of the foreach in a local variable, or recover the value saved in pos of the previous item
Thank you very much
Discussion posts and replies are publicly visible
Can you give more information? You need a specific iteration, a varying one or all of them?
As Yogi Patel is sort of hinting, you can use a!foreach functions like fv!isFirst, fv!isLast, fv!item and even fv!item-1 (-x) to move around the foreach iterations, more then that you can have local variables inside local variables like shown in his code snippet, the only thing is that local variables can only ba accessed inside it's own function so the variables inside the second localVariable function won't be accessed on the 'father' local variable function
Okay, so if the valor value is same then their pos will also be same right?