<?php
function show($arr, $prefix = '')
{
if (!is_array($arr))
{
if ($prefix)
{
echo $prefix . '->'. $arr, "\n";
}
else
{
echo $arr, "\n";
}
}
else
{
foreach ($arr as $key => $val)
{
$pre = $prefix;
if (is_array($val))
{
if ($pre)
{
$pre = $pre . '->' . $key;
}
else
{
$pre = $key;
}
show($val, $pre);
}
else
{
show($val, $pre);
}
}
}
}
$list = array(
'transport' => array(
'plane' => array(
'boeing',
'airbus',
),
'car' => array(
'audi',
'ford'
),
),
);
show($list);
输出:
transport->plane->boeing
transport->plane->airbus
transport->car->audi
transport->car->ford