我有2個數組。 一日一爲將數組內容寫入表
$people = array(
'person1' => array('name' => 'Ted', 'Year' => '68'),
'person2' => array('name' => 'Jane', 'Year' => '72'),
'person3' => array('name' => 'James', 'Year' => '46'),
'person4' => array('name' => 'Tim', 'Year' => '44'),
'person5' => array('name' => 'Ann', 'Year' => '39'),
'person6' => array('name' => 'Leyla', 'Year' => '45'),
'person7' => array('name' => 'Lucy', 'Year' => '41'),
'person8' => array('name' => 'Diana', 'Year' => '28'),
'person9' => array('name' => 'Tony', 'Year' => '10'),
'person10' => array('name' => 'Jane', 'Year' => '20'),
'person11' => array('name' => 'Alex', 'Year' => '30'),
'person12' => array('name' => 'Jane', 'Year' => '3'),
'person13' => array('name' => 'Ted', 'Year' => '27'),
'person14' => array('name' => 'Alex', 'Year' => '1'),
);
,第二個是
$genTree = array(
'families' => array(
array(
"mother" => 'person2',
"father" => 'person1',
'children' => array(
'person3',
'person4',
'person5'
)
)
),
'nextGeneration' => array(
'families' => array(
array(
'mother' => 'person6',
'father' => 'person3',
'children' => array(
'person8',
),
),
array(
'mother' => 'person7',
'father' => 'person4',
'children' => array(
'person9',
'person10'
)
),
),
'nextGeneration' => array(
'families' => array(
array(
'mother' => 'person8',
'father' => 'person11',
'children' => array(
'person12'
)
),
array(
'mother' => 'person10',
'father' => 'person13',
'children' => array(
'person14'
)
)
),
),
),
);
我需要得到每個家庭在新表中的數據每一代, 所以應該安排一個家譜
我試着做下一步,但不是我所需要的
function nameValues($array){
global $people; echo "<table border=1>";
foreach($array as $key=>$value)
{
echo "<tr>";
if(is_array($value))
{
nameValues($value);
}else{
echo "<td>".$key." ".$people[$value]['name']."</td>";echo "</tr>";
}
}
echo "</table>";
}
感謝您的幫助和explenation
你能提供的HTML輸出,你想看到的樣本?順便說一句,當你遞歸地調用'nameValues'時,它不會被放入'td'中,所以它會產生無效的HTML。 – megaflop