Jump to content

foreach but random?


rockinaway

Recommended Posts

I was thinking the same as Pikachu2000.

 

Basically, if I have $array1. And it has 5 values.

 

I want to loop through these values in a RANDOM order but retain their order in $array1.

 

So as Pikachu2000 stated, making a copy of the array to say $array2, shuffling it and then looping through it (not necessarily echoing anything) would work as then I can return to $array1 with everything preserved in the correct order.

 

I just want to know if there is a simpler way..

Link to comment
https://forums.phpfreaks.com/topic/238037-foreach-but-random/#findComment-1223384
Share on other sites

I was thinking the same as Pikachu2000.

 

Basically, if I have $array1. And it has 5 values.

 

I want to loop through these values in a RANDOM order but retain their order in $array1.

 

So as Pikachu2000 stated, making a copy of the array to say $array2, shuffling it and then looping through it (not necessarily echoing anything) would work as then I can return to $array1 with everything preserved in the correct order.

 

I just want to know if there is a simpler way..

there are other ways to do it, but as far as simplicity is concerned, the example that Pikachu2000 provided is what you want

Link to comment
https://forums.phpfreaks.com/topic/238037-foreach-but-random/#findComment-1223466
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.