Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Implode error

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Implode error

    Hey,
    I get this: Warning: implode() [function.implode]: Invalid arguments passed
    Once there is nothing in the array. (I use a while loop)
    If there is something in the array, it will work.

    Anyways, is there some way I can set a default value of...null?
    All I want is it to be empty instead of saying the above when it's empty, and when there's something in there, it does it (Which works fine).

    So what I'm asking is, how can I take away that error?
    Code:
    PHP Code:
    while($attach mysql_fetch_array($attachments))
            {
                
    $attachment[] = htmlentities($attach['file']);
            }
            
    $attachment implode(", "$attachment); 
    and the function:
    PHP Code:
    attachedFiles(); 
    Thanks!

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Crisp View Post
    So what I'm asking is, how can I take away that error?
    Do proper checks.

    Code:
    if (!empty($attachment))
    {
       $attachment = implode(", ", $attachment);
    }

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You can also just define $attachment as an array() before jumping into the while() loop. This ensures that $attachment will always exist as an array by the time you get to implode()... even when there is nothing to loop, which I believe is the case here. You will also avoid any "Undefined" notices that will undoubtedly be thrown.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •