This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Using a built in PHP function, we’ll choose four random items to suggest on the home page.
Increase Randomness
When using array_rand, the resulting array of keys is NOT shuffled, the books will always come before movies, which will come before music. If you want to randomize these even further you could use the shuffle function as well.
Example:
$random =array_rand($catalog,4); shuffle($random);
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up