1

I'm using a breadcrumb script for it's obvious use, and I am trying to remove &anyqueryafterhere from the result. I'm using for each to go through the array to remove this, but it returns 'Array'. The code I have is

if(empty($breadcrumbs)===false){
    foreach($breadcrumbs as &$r){
        $r = explode("&", $r);  
    }
}

Currently, it, as mentioned before, just returns Array, so it shows as something like Array » Array. So first question, what's the cause of this, and second, how can I sort it? Thanks in advance.

3
  • You realize that is only going to return the last $breadcrumbs right? You're overwriting $r with each iteration of the foreach loop. (that is after you remove that & from the foreach of course) Commented Dec 9, 2012 at 14:55
  • How exactly is he modifying anything in the above code? Other than overwriting $r of course. Commented Dec 9, 2012 at 14:58
  • 1
    He is overwriting $r by reference. In PHP, his line: $r = explode("&", $r) is the same as $breadcrumbs[$key] = explode("&", $r). He is modifying the source array because it is being passed by reference Commented Dec 9, 2012 at 15:02

2 Answers 2

2

try

foreach($breadcrumbs as &$r){
                        ^-----is reference operator ..remove this Those are references, they are similar to "pointers" in C or C++. 

foreach($breadcrumbs as $r){

and

if(empty($breadcrumbs)===false){

better approach will be

 if(!empty($breadcrumbs)){...}

Good Read

How does “&” operator work in PHP function?

Sign up to request clarification or add additional context in comments.

Comments

1

Replace

foreach($breadcrumbs as &$r){

With:

foreach($breadcrumbs as $r){

Remove the &.

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.