Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP For loop and random results

Featured Replies

I'm trying to get my for loop to display a new random number each time it loops. At the moment, it only displays the first number it generates ten times, instead of displaying ten random numbers once each. Is there a way to get the code to work how I want it to?

 

$num = mt_rand(1,100);
for ($i = 0;$i <$amount;$i ++)
{
echo $num."<br />";
}

Your $num variable is being set outside of the loop, and therefore will always be the same. It need to change in each iteration of the loop, so just put that variable inside. :)

 

for ($i = 0;$i < 10;$i ++)
{
$num = rand(1,100);
echo $num."<br />";
}

  • Author

Aah, I see now. I knew it was something simple. Thanks a lot! ^_^

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.