Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

shuffle an array

$
0
0

I can't figure out why my shuffle function is behaving the way it is. I've populated a multi-dimensional array $_SESSION['data']['question'][$count], $_SESSION['data']['answer'][$count], and $_SESSION['data']['type'][$count]. When I run the code without the shuffle function, it works properly by printing the question, answer and type data to the screen. But when I use the shuffle() function, my printout to the screen is blank. Thanks. Here is my code:

 

 

 

// Get and Assign Questions and Answers
$counter = 0;
$query3 = "SELECT * FROM inno_quiz_questions WHERE quiz_id = '".$row2['id']."' ORDER BY id";
$result3= mysql_query($query3) or die("Could not perform query: ".mysql_error());
$qnum = mysql_num_rows($result3);
while ($row3 = mysql_fetch_array($result3)){
   $_SESSION['data']['question'][$counter] = $row3['question'];
   $_SESSION['data']['answer'][$counter] = $row3['answer'];
   $_SESSION['data']['type'][$counter] = $row3['type'];
   $counter++;
}
 
shuffle($_SESSION['data']); // Shuffle array
 
$count = 0;
while ($count < $_SESSION['quiz']['assigned']){
   print $count.". ".$_SESSION['data']['question'][$count]."<br>";
   print $_SESSION['data']['answer'][$count]."<br>";
   print $_SESSION['data']['type'][$count]."<br><br>";
   $count++;
}
 

Viewing all articles
Browse latest Browse all 13200

Trending Articles