1 回答
TA贡献1875条经验 获得超3个赞
您的数组结构略有偏差,在
array(
"name" => "Jennifer Kimbers",
"age"=>"45",
"email" => "abc@gmail.com",
"city" => "Seattle",
"state" => "Washington"), // Close bracket here
array(
"job"=>"web developer"
),
这个缩进正确的是
array(
"name" => "Jennifer Kimbers",
"age"=>"45",
"email" => "abc@gmail.com",
"city" => "Seattle",
"state" => "Washington"),
array(
"job"=>"web developer"),
所以你的循环试图将它用作两个单独的数据位,而第二个不包含你期望的很多字段。
您需要确保在正确的位置关闭数组元素/将作业添加到与其余数据相同的元素中......
array(
"name" => "Jennifer Kimbers",
"age"=>"45",
"email" => "abc@gmail.com",
"city" => "Seattle",
"state" => "Washington", // Move ) after the job
"job" => "web developer"
),
如果您需要额外级别的数组,那么您可以将其列为工作列表......
array(
"name" => "Jennifer Kimbers",
"age"=>"45",
"email" => "abc@gmail.com",
"city" => "Seattle",
"state" => "Washington",
"jobs" => array( "title" => "web developer")
),
显示它们
foreach ($people as $person) {
echo "<tr>"
. "<td>" . $person ['name'] . "</td>"
. "<td>" . $person ['age'] . "</td>"
. "<td>" . $person ['email'] . "</td>"
. "<td>" . $person ['city'] . "</td>"
. "<td>" . $person ['state'] . "</td>"
. "<td>";
foreach ( $person['jobs'] as $job ) {
echo $job . "/";
}
echo "</td>"
. "</tr>";
}
虽然这样你最终会/在职位名称后面有一个尾随,但它显示了原则。您可以代替内部foreach()循环使用...
echo implode("/", $person['jobs']);
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报