0

Hello there guys so first of all, I have this code:

$crumbs = array();
$crumbs[] = "<a href=\"/\">Triple O Dental Laboratory</a>";

if (is_array($GLOBALS["cookie_crumbs"])) {
    foreach($GLOBALS["cookie_crumbs"] as $mycrumb) {
        $mycrumb[1] = str_replace("//","/",$mycrumb[1]);
        $crumbs[] = "<a href=\"".$mycrumb[1]."\">".$mycrumb[0]."</a> > <a href=\"#\">Smile TRU</a>";
    }
}

print "<div class=\"cookie_crumbs2\">\n";
print implode(" > ",$crumbs);
print "</div>\n";

Now the problem is, i am trying to remove this part of the code:

> <a href=\"http://stage.tripleodentallabs.com/laboratory/smile-tru/\">Smile TRU</a>";

But only from the LAST item in the array, so pretty much at the moment its getting output like this: http://puu.sh/74ure.png

But I want the " > big one" taken away from the last item which is "Accreditation Video".

1
  • 1
    by the looks of your code, it each array element in $crumbs will have two links one coming from array and <a href=\"#\">Smile TRU</a>". are you sure the only problem is last bit Commented Feb 21, 2014 at 11:40

2 Answers 2

1

Try this :

$crumbs = array();
$crumbs[] = "<a href=\"/\">Triple O Dental Laboratory</a>";

if (is_array($GLOBALS["cookie_crumbs"])) {
    foreach($GLOBALS["cookie_crumbs"] as $mycrumb) {
        if(end($GLOBALS["cookie_crumbs"] != $mycrumb)){
            $mycrumb[1] = str_replace("//","/",$mycrumb[1]);
            $crumbs[] = "<a href=\"".$mycrumb[1]."\">".$mycrumb[0]."</a> > <a href=\"#\">Smile TRU</a>";
        }
        else{
            $mycrumb[1] = str_replace("//","/",$mycrumb[1]);
            $crumbs[] = "<a href=\"".$mycrumb[1]."\">".$mycrumb[0]."</a>";
        }
    }
}

print "<div class=\"cookie_crumbs2\">\n";
print implode(" > ",$crumbs);
print "</div>\n";
Sign up to request clarification or add additional context in comments.

1 Comment

Edited the answer please check it
0

First count the crumbs and then, in the loop, check if You are handling the last one or not. Provided that the "cookie_crumbs" is array indexed numerically form 0:

$last = count($GLOBALS["cookie_crumbs"]) - 1;

foreach ($GLOBALS["cookie_crumbs"] as $index => $mycrumb) {

    if ($index === $last) {

        $crumbs[] = 'I am the last one'; // do whatever You need here...
    }
    else {

        $mycrumb[1] = str_replace("//","/",$mycrumb[1]);
        $crumbs[] = "<a href=\"".$mycrumb[1]."\">".$mycrumb[0]."</a> > <a href=\"#\">Smile TRU</a>";
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.