Output MySQL variables in PHP array -



Output MySQL variables in PHP array -

i have mysql variables, echoing want utilize them in array , randomly display results - it's competition - random working great can't variable show correctly when they're in array().

i have written following:

<?php $answer = array('$this->item->correct_answer','$this->item->false_answer1','$this->item->false_answer2'); shuffle($answer); ?> <ol class="answers"> <?php for( $i = 0; $i < 3; $i++) echo "<li>$answer[$i]</li>"; ?> </ol>

this outputting:

$this->item->correct_answer$this->item->false_answer2$this->item->false_answer1

that's because you've got ' array inputs. means you're setting string. revise to:

$answer = array($this->item->correct_answer,$this->item->false_answer1,$this->item->false_answer2);

as demonstrated on codepad.org

php mysql arrays

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -