I have a function which is called within a foreach loop and takes in two parameters, an integer, representing the number of times the loop has run and an array (of no fixed size).
I would like to return the value of the array key that is equal to the counter.
For example, if the array has four elements: A, B, C and D and the counter is equal to 2, it returns B. However, I’m trying to get the same result if the counter is equal to 6, 10, 14, 38, 3998 etc etc.
Is there a simple way to achieve this?
Any advice appreciated.
Thanks.
Note: I’m assuming you’re looping over an array of arrays, and passing that to your function. If that’s not the case, then just pass whatever array you need to pass instead of $whatever.