我有一個代碼塊,它可以完美地處理關於不同辦公室位置的數據。PHP foreach循環代碼更改的最後一次迭代
我想要做的是能夠使這個循環的最後一次迭代改變div類到別的東西,所以我可以應用一組不同的CSS樣式。
$fields = get_group('Offices');
foreach($fields as $field){
echo'<div class="oloc">';
if($locationVar==NULL || $locationVar!=$field['office-location'][1]) {
echo '<a name="' . strtolower(str_replace(' ', '-', $field['office-location'][1])) . '"></a><h3>' . $field['office-location'][1] . '</h3>';
$locationVar = $field['office-location'][1];
} else {
echo "<br />";
}
if($field['office-gm'][1]){
echo '<div class="gm"><img src="http://maps.googleapis.com/maps/api/staticmap?center=' . $field['office-gm'][1] . '&zoom=9&size=250x250&markers=color:blue|label:A|' . $field['office-gm'][1] . '&sensor=false"></div>';
}
if($field['office-name'][1]){
echo '<strong>' . $field['office-name'][1] . '</strong><br /><br />';
}
if($field['office-phone'][1]){
echo 'Phone: ' . $field['office-phone'][1] . '<br />';
}
if($field['office-fax'][1]){
echo 'Fax: ' . $field['office-fax'][1] . '<br />';
}
if($field['office-address'][1]){
echo '<br />Address:<br />' . strip_tags($field['office-address'][1], '<br><br />') . '<br />';
}
if($field['office-webpage'][1]){
echo 'Web: ' . '<a href="' . $field['office-webpage'][1] . '">Office Webpage</a><br />';
}
if($field['office-email'][1]){
echo 'Email: ' . '<a href="' . $field['office-email'][1] . '">Office Email</a><br />';
}
if($field['office-emp'][1]){
echo 'Jobs: ' . '<a href="' . $field['office-emp'][1] . '">Employment Application</a><br />';
}
if($field['office-fb'][1]){
echo 'Facebook: ' . '<a href="' . $field['office-fb'][1] . '">Facebook</a><br />';
}
if($field['office_office_twitter'][1]){
echo 'Twitter: ' . '<a href="' . $field['office_office_twitter'][1] . '">Twitter</a><br />';
}
echo '</div>';
}
看到這個問題:http://stackoverflow.com/q/665135/902654 – someone
根據您的預期水平的瀏覽器支持,你可以使用[':last-child'選擇器](http://reference.sitepoint.com/css/pseudoclass-lastchild) – Phil