0

I have some code which checks to see whether a certain variable is an array. If it is, I would like to assign all the array values to a single, comma-separated PHP variable. Here is the code:

if (is_array($value)) {         
    //Need to assign the array variables to the PHP variable $files, but how?
    $postdata.=$files;          
} else {
    $postdata.=$value;
}  

I have tried to use $files = print_r(array_values($value)); but it does not seem to work for me. What am I doing wrong? Thanks.

4
  • 6
    $postdata .= implode(", ", $files); perhaps? Commented Apr 25, 2013 at 20:41
  • Check out implode(). Commented Apr 25, 2013 at 20:41
  • I was just writing that. @bwoebi Commented Apr 25, 2013 at 20:41
  • sounds like you want implode() Commented Apr 25, 2013 at 20:41

2 Answers 2

4

Try:

$string = implode(',', $array);
Sign up to request clarification or add additional context in comments.

Comments

3

Add this line: $files= implode(',', $value);

2 Comments

lol, I hate it when I leave SO page too long before posting an answer, so that my answer looks exactly as if I copied someone who posted the correct answer a fews mins before!
the quick and the dead :-0\

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.