Jump to content

Implode Function?


sam139

Recommended Posts

I am getting this error message, "Warning: implode() [function.implode]: Invalid arguments passed in/home/sam139/public_html/_import/functions.php on line 235" and I have no idea where I'm going wrong. The code where the issue is occurring is

 <p class="bline"><strong>Cast: </strong> <?= implode("<br/>", $p['cast']); ?></p>

 

Where am I going wrong? Any help is much appreciated! 

Link to comment
Share on other sites

The second argument needs to be an array. Sounds like $p['cast'] is not an array. You can do a var_dump on it to see what it does contain. Before trying to use an argument in a function that needs an array, if there's any chance it's not, I always test it first. (I usually use count() because I don't want to use it even if it is an array and has no values.)

Link to comment
Share on other sites

Well, per the documentation for implode() there are two parameters (note: it can also take a single parameter, but that's not commonly used):

 

string implode ( string $glue , array $pieces )

 

glue: Defaults to an empty string.

 

pieces: The array of strings to implode.

 

Your first parameter is obviously a string. So,the problem has to be the second parameter: $p['cast']. Have you verified the contents of that variable and ensured it is, in fact, an array?

Link to comment
Share on other sites

Yes, I believe it is an array

 

"Believing" something is true and "knowing" are two different things. It is apparent that it is NOT an array - else you would not be getting the error. You can very easily verify that it is or is not an array using the function is_array().

 

if(is_array($p['cast'])){
    echo "it's an array";
} else {
    echo "it's NOT an array";
}

 

But, we already know it is not an array. So, you might as well look to see where it is defined.

Edited by Psycho
Link to comment
Share on other sites

Yes, I believe it is an array, because this code was working fine for a while. How can I check for sure?

Responses like this are why 99% of the time, I don't write as much as I did in my reply. Did you even read it? It's like, why do I waste my time actually telling to how to do it, when you're just going to ask how to do it?
Link to comment
Share on other sites

Ya, I read your response several times, and I apologize for wasting your time. I'm not very savvy with this stuff. I just wanted to know how I could check. I don't do PHP, but I was told to fix this problem.

 

Thanks everyone, I obviously need to look into this further.

Link to comment
Share on other sites

The second argument needs to be an array. Sounds like $p['cast'] is not an array. You can do a var_dump on it to see what it does contain. Before trying to use an argument in a function that needs an array, if there's any chance it's not, I always test it first. (I usually use count() because I don't want to use it even if it is an array and has no values.)

I told you the way to check what the variable is, and a way to specifically avoid this error.

 

 

 

The bigger problem is you need to trace back to when the variable is created. If you don't "do" php, you should tell whoever told you to fix it that you either need time to learn, or they should pay someone who DOES know PHP.

Link to comment
Share on other sites

I don't think hiring someone to fix one line of code is necessary, but I'm not the expert.

 

As we've stated the error is NOT that line. The problem is in how $p['cast'] is defined - or probably not defined in this case. So, unless you know where that it is, it may take someone who understands PHP to analyze the code to figure out where it is supposed to be defined and trace back what that problem is.

Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.