[ create a new paste ] login | about

Link: http://codepad.org/4Zhr9Wje    [ raw code | output | fork ]

PHP, pasted on Apr 19:
<?php 

$line = 'What is a dog?, A pet, A human, A house, A train';

    //This cose assumes no commas in the question or answers.
    $answers = explode(',', $line);

    //pull the question into a variable
    $question = $answers[0];

    //remove the question from the list of answers
    array_shift ($answers);

    //add the array to your result array
    $quizItems[]=array('question'=>$question, 'answers'=>$answers );

$line = 'What is a car?, A vehicle, A tool, A number, A person';

    //This cose assumes no commas in the question or answers.
    $answers = explode(',', $line);

    //pull the question into a variable
    $question = $answers[0];

    //remove the question from the list of answers
    array_shift ($answers);

    //add the array to your result array
    $quizItems[]=array('question'=>$question, 'answers'=>$answers );


foreach ($quizItems as $quizItem){
    echo '<b>'.$quizItem['question']."</b>\n".
         implode("\n", $quizItem['answers'])."\n\n\n";
}
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<b>What is a dog?</b>
 A pet
 A human
 A house
 A train


<b>What is a car?</b>
 A vehicle
 A tool
 A number
 A person




Create a new paste based on this one


Comments: