我创建了一个带有多个值的键的哈希,并且不确定如何打印它们以获得我想要的输出。我的哈希如下:
Array
(
[developmental stage] => Array
(
[0] => dummy development1
[1] => dummy development
)
[treatment] => Array
(
[0] => dummy treatment1
[1] => dummy treatment
)
[age] => Array
(
[0] => dummy age
)
)
The expected output:
developmental stage treatment Age
dummy development1 dummy treatment1 dummy age
dummy development dummy treatment
创建哈希的代码:
$attribute[$property->type_id->name][]=$property->value;
我尝试的代码如下。如何按上述方式打印?
foreach ($attribute as $key=>$value) {
echo "$keys\t";
foreach($key=>$value as $key1){
echo "$key1\n";
}
echo "\n";
}
答案 0 :(得分:1)
尝试做这样的事情:
function printArray($array = array()) {
foreach ($array as $key => $value) {
if (is_array($value)) {
printArray($value)
} else {
echo $key.'=>'.$value."\n";
}
}
}
printArray($yourArray);