Jump to content

Recommended Posts

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)"

Link to comment
https://forums.phpfreaks.com/topic/65302-solved-php-implode-error/
Share on other sites

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'.

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.

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.