0

So supposing I have this array

$arr = array(0 =>"joy", 1=>"boss",2=>"salt",3=>"man",4=>"fish",5=>"bye",6=>"bye",7=>"bye");

I want to reorder the array to look something like this

$arr = array(0 =>"bye", 1=>"boss",2=>"bye",3=>"man",4=>"bye",5=>"fish",6=>"salt",7=>"joy");

I'm trying to avoid the shoffle function because of the probability of getting something like 1=>"bye",2=>"bye" which is what I'm trying to avoid completely.

Any suggestions?

Felibrain
  • 9
  • 3
  • 1
    I think you are looking for this https://stackoverflow.com/questions/25285792/generate-all-permutations-of-a-list-without-adjacent-equal-elements – Meg Aug 17 '21 at 18:01
  • Does this answer your question? [Generate all permutations of a list without adjacent equal elements](https://stackoverflow.com/questions/25285792/generate-all-permutations-of-a-list-without-adjacent-equal-elements) – Ross Presser Aug 17 '21 at 18:55
  • Unfortunately no. And I should mention that I am working with php. – Felibrain Aug 17 '21 at 20:04

0 Answers0