0
我想通过使用foreach循环找到数组中的最后一个元素。如何找到数组的最后一个元素
我..
foreach ($employees as $employee) {
$html.=$employee ->name.'and ';
}
我不希望添加“和”最后的雇员。有没有办法做到这一点?非常感谢!
我想通过使用foreach循环找到数组中的最后一个元素。如何找到数组的最后一个元素
我..
foreach ($employees as $employee) {
$html.=$employee ->name.'and ';
}
我不希望添加“和”最后的雇员。有没有办法做到这一点?非常感谢!
比在你的foreach中有一个计数器更清洁的方法可能是简单地删除字符串的最终“和”。
foreach ($employees as $employee) {
$html .= $employee->name . 'and ';
}
$html = substr($html, 0, strlen($html) - 4);