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?

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)?

Member Avatar for diafol

Use array and then the shuffle() function.

Can you give some examples for that?

Member Avatar for diafol

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

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 />';

            }

        }

    }


?>
Member Avatar for diafol
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
shuffle($data);

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));

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.