如何打印此阵列?
<?php
$datos = array(
array('AZUAY', array('P', 'Q'))
);
//print array
foreach ($datos as $dato1) {
foreach ($dato1 as $v2) {
echo $v2;
foreach ($v2 as $v3)
echo $v3;
}
echo "<br>";
}
?>
答案 0 :(得分:2)
您可以将printf()
或var_dump()
用作简单的漂亮打印机:
print_r($datos);
var_dump($datos);
输出:
<强> print_r()
强>
Array ( [0] => Array ( [0] => AZUAY [1] => Array ( [0] => P [1] => Q ) ) )
<强> var_dump()
强>
array(1) { [0]=> array(2) { [0]=> string(5) "AZUAY" [1]=> array(2) { [0]=> string(1) "P" [1]=> string(1) "Q" } } }
答案 1 :(得分:0)
这样的事情应该有效:
$datos = array(
array('AZUAY', array('P', 'Q'))
);
function printWeirdArray($array)
{
foreach($array as $i)
{
if(is_array($i))
{
printWeirdArray($i);
}
else
{
print $i."-";
}
}
}
printWeirdArray($datos);
以上代码输出:
AZUAY-P-Q-