Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to shuffle questions using php?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24769
    ahlerjrs
    Participant

    I have a set of questions that are located in a XML file. Using php, I need to pull the questions from the XML file and shuffle the order of the questions each time they are displayed to the user.

    What is the best way to implement this?

    Please be specific in your instructions and syntax because I am fairly new to php programming?

    Thank you!
    John

    #57084
    Chris Coyier
    Keymaster

    If JavaScript is an option, I recently used James Padolsey’s DOM shuffler to shuffle questions on a quiz thingy for a client:

    http://james.padolsey.com/javascript/shuffling-the-dom/

    I’m sure there is a PHP way to, which is probably smarter, but I’m not super hot with my PHP skillz =)

    #57108
    ahlerjrs
    Participant

    Hi Chris,

    Thank you for the information!

    John

    #149658
    Migotn
    Participant
    #149659
    Migotn
    Participant

    ahlertjrs,

    In php, one of the options would be to store the questions in an array and the use shuffle() function to assist in doing what you trying to achieve.

    <?php
    $question_array = array("Qa","Qb","Qc","Qd","Qe");
    
    //Shuffle the array of questions
    shuffle($question_array);
    
    //print out the arrays to your screen or you may opt to save them yet to another array or variable for later use
    print_r($question_array);
    ?>
    
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.