SJames Posted August 16, 2007 Share Posted August 16, 2007 I have the following code, a simple implode function: $titles = $_POST['titles']; $titles = implode("#", $titles); I am positive that "$titles" is an array, but I get an error message from PHP saying: Warning: implode() [function.implode]: Bad arguments. in /home/.... on line 12 *I replaced the rest of the URL with "...." to save space. Does anyone know why I'm getting this error? I've also tried removing the first value from the function, so it would read "implode($titles)". Using another variable with the implode doesn't work either, eg: "$newVariable = implode("#", $titles)" Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/ Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Do a print_r($titles) and post the result, please. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326109 Share on other sites More sharing options...
d22552000 Posted August 16, 2007 Share Posted August 16, 2007 it will probably print: "array()" Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326116 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 I wrote: $titles = $_POST['titles']; print_r($titles); I received: Array Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326118 Share on other sites More sharing options...
d22552000 Posted August 16, 2007 Share Posted August 16, 2007 told ya. That's a valid array alright. Check on php.net for implode and check your syntax. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326120 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 I did, I did it exactly the same, I still get the error.... Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326124 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Doesn't that mean it is an array with nothing in it? Wouldn't that mean it can't implode anything? If you do a print_r($_POST), does it show titles as a subarray? Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326130 Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 if you receive "Array" and that's it when you run print_r() on the variable, it means you've got an empty array. you may want to run a check to see if it's both an array and is NOT empty: if (is_array($titles) && !empty($titles)) { $titles = implode('#', $titles); } EDIT: it just dawned on me - if there are no parentheses after "Array", you probably actually just have a string with the value 'Array'. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326132 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 print_r($_POST) shows it as an array Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326137 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 I guess that doesn't really mean anything, I don't remember what I was getting at with that. You have a problem with your input from POST. Could you post the code that passes the array to your php file with POST? Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326139 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 Hmmm... I did your suggestion, it appears that the array is empty, but part of the code is a foreach() that shows the contents of the array, and the values are indead inside. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326143 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 Didn't you just post a thread saying that your foreach function wasn't working? If you show some code it will be a lot easier for people to help you. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326147 Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 if you're trying to run a foreach() on $titles AFTER using implode(), you're going to have problems because in the process of imploding (if it actually works), you've converted the array to a string due to the same variable name being used. Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326149 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 those are actually two seperate projects, they just both have a $titles variable Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326153 Share on other sites More sharing options...
SJames Posted August 16, 2007 Author Share Posted August 16, 2007 Never mind, I got it working: The page that puts the values into the array wasn't doing it right. Thanks for helping! Quote Link to comment https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/#findComment-326165 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.