for example I have an array :
$array = array(25, 50, 75, 100); // I get an array of some numbers
$position = 50; // I get some value to start with
$limit = 3; // I need to fill another array with 3 next values from the starting position
and now what code I need to use to fill a new array just like this:
$new_array = array(75, 100, 25); // the start position is 50, but I need the next 3
any ideas??
I like having functions to abstract the logic. So I would suggest to write a function which takes the array, the position to start with and the limit:
So now you can call the function with any value you want, e.g.:
outputs
Or you could loop it with any other values:
Here’s a working example: http://codepad.org/lji1D84J