Skip to content

Instantly share code, notes, and snippets.

@e2thex
Created May 16, 2012 15:56
Show Gist options
  • Select an option

  • Save e2thex/2711570 to your computer and use it in GitHub Desktop.

Select an option

Save e2thex/2711570 to your computer and use it in GitHub Desktop.
What PHP fun fact make the use of $last here horribly wrong?
<?php
$output = '<div id="breadcrumb" class="clearfix"><ul class="breadcrumb">';
$switch = array('odd' => 'even', 'even' => 'odd');
$zebra = 'even';
$last = count($variables['breadcrumb']) - 1;
foreach ($variables['breadcrumb'] as $key => $item) {
$zebra = $switch[$zebra];
$attributes['class'] = array('depth-' . ($key + 1), $zebra);
if ($key == 0) {
$attributes['class'][] = 'first';
}
if ($key == $last) {
$attributes['class'][] = 'last';
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $item . '</li>';
}
$output .= '</ul></div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment