Jump to content

Variables Inside Variables


Recommended Posts

$q1{$questions[0]}++;

 

Would that work?

 

Whats drawn from the database is question answers 1-5. So I have variables like $q11 $q12 $q13 $q14 $q15 and I want to just be able to easily increment one without the use of if statements. So I was hoping to do $q1$answer to incrent say $q12 if the answer is 2.

maybe something like this

 

<?php

$q[1] = "What says meow!";
$a[1][1] = array("Cat",true);
$a[1][2] = array("Dog",false);
$a[1][3] = array("Snake",false);


foreach($q as $k => $qs)
{
echo $qs;
shuffle($a[$k]);
foreach($a[$k] as $L)
{
echo $L[0];
if($L[1]) echo "Correct";
echo "<br>";
}
}
?>

 

EDIT: this is untested

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.