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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.