sam139 Posted March 11, 2013 Share Posted March 11, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/ Share on other sites More sharing options...
Jessica Posted March 11, 2013 Share Posted March 11, 2013 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.) Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417969 Share on other sites More sharing options...
Psycho Posted March 11, 2013 Share Posted March 11, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417970 Share on other sites More sharing options...
sam139 Posted March 11, 2013 Author Share Posted March 11, 2013 Yes, I believe it is an array, because this code was working fine for a while. How can I check for sure? Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417971 Share on other sites More sharing options...
Psycho Posted March 11, 2013 Share Posted March 11, 2013 (edited) 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 March 11, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417974 Share on other sites More sharing options...
Jessica Posted March 11, 2013 Share Posted March 11, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417978 Share on other sites More sharing options...
sam139 Posted March 11, 2013 Author Share Posted March 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417981 Share on other sites More sharing options...
Jessica Posted March 11, 2013 Share Posted March 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417983 Share on other sites More sharing options...
sam139 Posted March 11, 2013 Author Share Posted March 11, 2013 I don't think hiring someone to fix one line of code is necessary, but I'm not the expert. Thanks again, I got it. Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417990 Share on other sites More sharing options...
Psycho Posted March 11, 2013 Share Posted March 11, 2013 (edited) 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 March 11, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/275509-implode-function/#findComment-1417992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.