PHP - 在PHP中打印数组的值

问题描述 投票:0回答:1

我如何循环'ques_title'的值?下面是代码及其输出,我甚至尝试使用循环值,即$ i => $ value但是没有显示输出。

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"
}
}

我想循环遍历所有变量并存储它们。我该怎么做 ?

php arrays loops for-loop foreach
1个回答
1
投票
foreach($allquiz as $i) {
    echo "<pre>";
    print_r($i["'ques_title'"]);
    echo "</pre>";
}
© www.soinside.com 2019 - 2024. All rights reserved.