I would like to randomize an array which contains stdClasses as value for every key and the stdclasses order must be the original.
for example the original array looks like this:
Array(
[0]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=1 [name]=One*/)
[1]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=2 [name]=Two*/)
[2]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=3 [name]=Three*/)
[3]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=4 [name]=Four*/)
)
and this is what I would like to achive:
Array(
[3]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=4 [name]=Four*/)
[0]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=1 [name]=One*/)
[1]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=2 [name]=Two*/)
[2]=>stdClass(/*lots of keys with value that must stay here and stay in order
for example [id]=3 [name]=Three*/)
)
I tried this function PHP Random Shuffle Array Maintaining Key => Value but this shuffels the stdClasses too and thats not good.
for example zero key’s class->id is shuffeld to third key
And I don’t know how to randomize this in the right way.
This will shuffle your array and maintain key/value association.