Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 600865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:39:09+00:00 2026-05-13T16:39:09+00:00

<?php if (isset($_POST[‘Roll!’])) { $sides = $_POST[‘sides’]; $rolled = rand(1,$sides); echo $rolled was rolled

  • 0
<?php
        if (isset($_POST['Roll!'])) {
                    $sides = $_POST['sides'];
                    $rolled = rand(1,$sides);

                    echo "$rolled was rolled by the dice, it is now out!";
        }
?>

This is the code I currently have. After rolling that number, however, I want it to roll again, but without the previously rolled number, until it has rolled all number except one, which would be the winning number. I have no idea how to go about doing that. Any ideas?

EDIT: I’m sorry, I should have been more clear, thank you all for the help so far, but I also need to echo each number rolled, such as

echo "$rolledArray[0] was rolled, it lost.\n";
echo "$rolledArray[1] was rolled, it lost.\n";
echo "$rolledArray[2] was rolled, it lost.\n";
echo "$rolledArray[3] was rolled, it lost.\n";
echo "$rolledArray[x] was rolled, it lost.\n";
echo "$rolledArray[x] was rolled, it lost.\n";
echo "$rolledArray[50?] was rolled, it lost.";

EDIT AGAIN: Also I only want them to have to click Roll! once, not multiple times until they’ve rolled all the numbers, meaning no need for session, I think, though I could be wrong, most of you are clearly more experienced than me.

Sorry, I should have mentioned that before as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:39:09+00:00Added an answer on May 13, 2026 at 4:39 pm

    To answer your direct question:
    You can put all of the possible numbers into an array, and get a random index for that array. Once you have an index, remove the item from the array and redo the random over the smaller array:

    $possible = range(1, $_POST['sides']);     // build the possible values
    $rolledIndex = rand (0, count($possible)); // get a random index
    $rolled = $possible[$rolledIndex];         // get the rolled number
    
    unset($possible[$rolledIndex]);            // and remove the rolled nuber
    
    // now you can simply redo the random:
    $rolledIndex = rand (0, count($possible)); // get a random index on the smaller array
    $rolled = $possible[$rolledIndex];         // get the 2nd rolled number
    

    However, If you want to have a random order on the dice throws, simply use this:

    // generate an array with all values from 1 to the posted value (e.g. 1,2,3,4,5,6)
    $possible = range(1, $_POST['sides']);  
    
    // this reorders the array by random (e.g. 4,3,1,5,2,6)
    $throwOrder = $possible;
    shuffle($throwOrder); 
    print_r($throwOrder);
    

    Now you can simply iterate over the $throwOrder array and have a random order of dice throws:

    Array (
        0 => 4,
        1 => 3,
        2 => 1,
        3 => 5,
        4 => 2,
        5 => 6
    )
    

    Edit To get the desired output from the second method, simply do this:

    // get the last index of the array of thrown dices
    $lastIndex = count($throwOrder)-1;
    // iterate through the array, printing the results
    foreach ($throwOrder as $key => $rolled) {
        // check if the current key matches the last key in the array
        if ($key != $lastIndex) {
            // if not, the number has lost
            echo $rolled, " was rolled, it lost.\n";
        } else {
            // we have reached the last element of the array
            echo $rolled, " was the last, it won.\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think it is possible to delete without locking.… May 13, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer When generating the proxy from WSDL there is an option… May 13, 2026 at 5:37 pm
  • Editorial Team
    Editorial Team added an answer Actually the main difference between Sharepoint and Drupal is that… May 13, 2026 at 5:37 pm

Related Questions

Take this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
For example i use this little code: <?php if (isset($_POST['Submit'])){ if ((@$_POST['Submit'] == 'x'))
<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $dbhost = 'localhost'; $dbuser = 'zuk1_boo'; $dbpass
i have this image upload script. <?php if(isset($_POST['submit'])){ if (isset ($_FILES['new_image'])){ $imagename = $_FILES['new_image']['name'];
<?php session_start(); include(connect.php); $timeout = 60 * 30; $fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); if(isset($_POST['userName']))

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.