我有一个数组列表,需要它们用 printf 语句输出
<?php
$example = array("first" => "Bob", "last" => "Smith", "address" => "123 Spruce st" );
$example = array("first" => "Sara", "last" => "Blask", "address" => "5678 Maple ct" );
foreach ($example as $key => $val) {
printf("<p>hello my name is %s %s and i live at %s</p>",$example['first'],$example['last'], $example['address']);
}
?>
以上只是输出最后一个数组,我需要它遍历所有数组并<p>
使用提供的key => value
组合生成 a 。这只是一个简化的例子,因为真实世界的代码在输出中会更复杂html
我试过
foreach ($example as $arr){
printf("<p>hello my name is %s %s and i live at %s</p>",$arr['first'],$arr['last'], $arr['address']);
}
但它只为每个输出一个字符key => value