[英]Printing key with multiple value php
I have created a hash with keys that have multiple value's and not sure how to print them to get my desired output. 我用具有多个值的键创建了一个哈希,并且不确定如何打印它们以获取所需的输出。 My hash is as follows:
我的哈希如下:
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
Code to create the hash: 创建哈希的代码:
$attribute[$property->type_id->name][]=$property->value;
Code that I have tried is as below. 我尝试过的代码如下。 How do I get it to print as stated above?
我如何如上所述打印它?
foreach ($attribute as $key=>$value) {
echo "$keys\t";
foreach($key=>$value as $key1){
echo "$key1\n";
}
echo "\n";
}
Try to do something like this: 尝试做这样的事情:
function printArray($array = array()) {
foreach ($array as $key => $value) {
if (is_array($value)) {
printArray($value)
} else {
echo $key.'=>'.$value."\n";
}
}
}
printArray($yourArray);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.