What exactly is the difference between shuffle and array_rand functions in PHP? Which is faster if there is no difference.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When called on an array,
shufflerandomizes the order of all elements of that array.For example, the following portion of code :
Could give this output :
The whole array itself gets modified.
When called on an array, **[`array_rand`][2] returns one or more keys from that array, randomly selected**.
For example, the following portion of code :
Could give tis kind of output :
A sub-array of the initial array is returned — and the initial array is not modified.