silkfire Posted August 1, 2011 Share Posted August 1, 2011 How does one create a function that shuffles a numerical array X amount of steps? Example: $array = array('item1', 'item2', 'item3', 'item4'); $array = array_shuffle($array, 2); Result should be: array('item3', 'item4', 'item1', 'item2') Function looks like: array_shuffle($array, $steps, $direction = 1); $direction is 1 for forward or 0 for backwards. Is this hard? Link to comment https://forums.phpfreaks.com/topic/243506-array-shuffle-with-step/ Share on other sites More sharing options...
gizmola Posted August 1, 2011 Share Posted August 1, 2011 No, you just need to use a combination of array_pop and array_unshift in one direction and array_shift and array_push in the other. Link to comment https://forums.phpfreaks.com/topic/243506-array-shuffle-with-step/#findComment-1250326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.