Check the
javascript documentation for the details.
Anyway the function does the following: php already has a
built in shuffle function, so my
shuffleArray javascript was not needed to be implemented in php anew.
Yet, php has no
symmetrical shuffle built in function.
By this
neologism, symmetrical shuffle, I mean to address an exigency that once I was requested to solve, namely the possibility, upon shuffling an array, to maintain the symmetry (entry by entry correspondences, that is) that other arrays had with it
before the shuffling process. So, the function takes in a set of subsequent arrays, and shuffles them all accordingly to the same process, so that all the original correspondences among the original arrays are preserved though they undergo a reshuffling.
Unlike its javascript equivalent, this function takes as arguments only
two arguments: an array which must be a list of arrays (that is, an array whose each entry is one of the arrays that must be shuffled), and one more arguments that in the javascript version corresponds to the one named
recursive (that is, to repeat the shufflings
X times).
Differences in the
lengths of the passed arrays do
not impair the function: it will manage that.
The reason the javascript accepted more is that a javascript is released by definition upon a promiscuous environment for it must be able to work also under generic user inputs: thus it must be very flexible, and account for a range of possible different (maybe even misunderstood) inputs. With php, being entirely on
server side namely
hidden from the General User Interfaces, we may perhaps safely assume the scripters are more aware of and competent about the restraints a function signature imposes.
The arrays must be passed as one array (that is, an array whose each entry is one of the arrays to be symmetrically shuffled). A second argument named recursive allows more shufflings. Unlike in the javascript version, here a max recursion cycles has been set to 50 rounds at most, to avoid crashes of the server.
Returns an array of arrays: each of the listed arrays is a symmetrically shuffled array.
The function named
sortMultishaffle is the more powerful parallel shuffling function with quicksort support. Given the way PHP works, I had to split it into two functions plus two globally defined variables. Yet you still invoke it as you invoked its equivalent javascript, and has its same limtations namely the
sizes of the arrays must be
identical:
sortMultishuffle($arrayOfArrays_here);