我需要一个PHP函数来输出任何关联或索引数组。 我有一个关联数组和我创建的函数的例子。
function print_assoc_array(){
$cars = array(
array('Car_brand' => 'Ford', 'Model' => 'Focus', 'Age' => '5 years'),
array('Car_brand' => 'Skoda', 'Model' => 'Octavia', 'Age' => '3 years')
);
foreach ($cars as $key => $value) {
echo $value['Car_brand'] . " " . $value['Model'] . " " . $value['Age'] . "<br/>";
}
}
print_assoc_array();
任何帮助将不胜感激!
答案 0 :(得分:0)
尝试此功能,如果它可以帮助你。
function print_assoc_array()
{
$cars = array(
array('Car_brand' => 'Ford', 'Model' => 'Focus', 'Age' => '5 years'),
array('Car_brand' => 'Skoda', 'Model' => 'Octavia', 'Age' => '3 years')
);
foreach ($cars as $key => $value) {
foreach($value as $ke=>$val)
{
echo $val." ";
}
echo "<br />";
}
}
print_assoc_array();