0

HI,

I am trying to do questions generation system in PHP. I need some idea form all of you, how to shuffle questions and answers from table based on standard, section, subject,difficulty of question (Easy, Medium, High),No of module (Like, choose the best anser, true or false, Explanation ), and Choices for each module, etc,
By your ideas only, I am going to do this concept., How to do shuffle the question?
Can you tell me with some examples?
with some easy logic for shuffling questions?

5
Contributors
7
Replies
36
Views
1 Year
Discussion Span
Last Post by parvez alam
0

How about save your questions in an array, so that you can shuffle it by swapping 2 questions at a time for a number of times (i.e. 1000 times)?

0

Use array and then the shuffle() function.

0

Seriously? You don.t have access to the php manual?

1

A simple ideea with multi dimensional array.

<?php

    /*
    Static questions

    You could get dinamyc content from a database 
    */
    $questions = array(
        'Where are located penguins' => array(
                            'Answers' => array(
                                'North Pole',
                                'South Africa',
                                'England',
                                'Moon'
                            )
        ),
        'How do you find a street?' => array(
                            'Answers' => array(
                                'Google Maps',
                                'Ask someone',
                                'Pay a detective',
                                'Sit in a chair an try to rememeber location'
                            )   
        )
    );

    foreach ($questions as $qkey => $qvalue) {

        print '<h3>'.$qkey.'</h3>';

        foreach ($qvalue as $ekey => $evalue) {

            print '<p>'.$ekey.':</p>';

            foreach ($evalue as $akey => $avalue) {

                print $avalue.' <br />';

            }

        }

    }


?>
2
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
shuffle($data);
1

You can try this sample code as well to suffle php array values.
$my_array = array("red","green","blue","yellow","purple");

print_r(shuffle($my_array));

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.