使用PHP,如何在我的网页中输出/显示此数组中的值:
答案 0 :(得分:3)
看起来像print_r()输出给我。
答案 1 :(得分:1)
使用foreach语句迭代遍历每个回显的数组
foreach($data as $k => $v) {
echo "{$k} => {$v}";
}
$ data是输入数据 $ k是关键$ v是$ value
以上仅适用于数组数组的单个深度数组,例如示例数据,只要您需要使用递归函数,然后检查该值是否为数组,如果这样,则以递归方式调用该函数。
如果数据结构永远不会改变,那么一些嵌套循环将完成这项工作。 (有些人认为递归是邪恶的,我可怜他们)
DC
答案 2 :(得分:0)
$myarray = array(
"Key1" => "This is the value for Key1",
"Key2" => "And this is the value for Key2"
);
print_r($myarray);
/* or */
var_dump($myarray);
print $myarray["Key1"]; // Prints 'This is the value for Key1'
print $myarray[0]; // Prints 'This is the value for Key1'