topper1309
topper1309

Reputation: 151

PHP - Printing values of array in PHP

How will I loop the values of 'ques_title' ? Below is the code and its output, I even tried with looping the value i.e $i => $value but then no output is shown.

foreach($allquiz as $i) {
    echo "<pre>";
    print_r($i);
    echo "</pre>";
}

OUTPUT

Array
(
['ques_title'] => Ques 1
['ques_image'] => kitchenaid_mixer_ele_qNhwH.png
['choice_1'] => iphone7_rosegold.png
['choice_2'] => kitchenaid_mixer_ele_qNhwH.png
['choice'] => choice_2
['choice_3'] => iphone7_rosegold.png
['choice_4'] => iphone7_rosegold.png
['question_type'] => 1
)
Array
(
['ques_title'] => Q2
['ques_image'] => 
['choice_1'] => f
['choice_2'] => s
['choice_3'] => t
['choice_4'] => f
['question_type'] => 0
)

var_dump($allquiz);

OUTPUT:

array(2) {
 [0]=>
array(8) {
["'ques_title'"]=>
string(11) "qdea sdas d"
["'ques_image'"]=>
string(30) "kitchenaid_mixer_ele_qNhwH.png"
["'choice_1'"]=>
string(20) "iphone7_rosegold.png"
["'choice_2'"]=>
string(30) "kitchenaid_mixer_ele_qNhwH.png"
["'choice'"]=>
string(8) "choice_2"
["'choice_3'"]=>
string(20) "iphone7_rosegold.png"
["'choice_4'"]=>
string(20) "iphone7_rosegold.png"
["'question_type'"]=>
string(1) "1"
}
[1]=>
 array(7) {
 ["'ques_title'"]=>
string(10) "Q2sad asas"
["'ques_image'"]=>
string(0) ""
["'choice_1'"]=>
string(1) "f"
["'choice_2'"]=>
string(1) "s"
["'choice_3'"]=>
string(1) "t"
["'choice_4'"]=>
string(1) "f"
["'question_type'"]=>
string(1) "0"
}
}

I want to loop through all the variables and store them. How can I do it ?

Upvotes: 0

Views: 70

Answers (1)

Artem Lopatin
Artem Lopatin

Reputation: 41

foreach($allquiz as $i) {
    echo "<pre>";
    print_r($i["'ques_title'"]);
    echo "</pre>";
}

Upvotes: 1

Related Questions