need some guidence with this...

Hello, I’m more of an HTML/Graphics guy, but have used PHP off-on for a number of years. I have a client with a CMS-based website that has an inventory page in which there is a list of car makes displayed (i.e. Chevy, Dodge, Ford, etc.) on the page’s nav bar…

The list is displayed alphabetically, but the client wishes to have one of the makes appear at the top of the list on the nav bar, but keep the remainder of the list alphabetized on the page…

So for example what is now:

  1. Austin-Healy
  2. Cadillac
  3. Chevy
  4. Dodge
    etc…

would be:

  1. Chevy
  2. Austin-Healy
  3. Cadillac
  4. Dodge
    etc…

Here’s the existing code:

VIEW BY MAKE

  • <?php echo anchor('inventory','All Makes','') ?>
  • <?php foreach ($makes as $m) : ?> <?php $class = ($m->make == urldecode($this->uri->segment(3))) ? 'class="make-selected"' : ""; ?>
  • <?php echo anchor('inventory/make/' . $m->make, $m->make, "$class"); ?>
  • <?php endforeach; ?>

Thanks for any help with this!

You could do something like this

[php]
$values = array(‘Austin-Healy’,‘Cadillac’,‘Chevy’,‘Dodge’);
foreach($values as $key => $value) {
if ($value === ‘Chevy’) {
unset($values[$key]); // remove Chevy from the values array
break; // stop the loop so $value is retained
}
}
array_unshift($values, $value); // prepend $value
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service