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:
我有一些代码检查某个变量是否是一个数组。如果是,我想将所有数组值分配给一个逗号分隔的PHP变量。这是代码:
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.
我试过使用$ files = print_r(array_values($ value));但它似乎对我不起作用。我究竟做错了什么?谢谢。
2 个解决方案
#1
4
Try:
尝试:
$string = implode(',', $array);
#2
3
Add this line: $files= implode(',', $value);
添加以下行:$ files = implode(',',$ value);
#1
4
Try:
尝试:
$string = implode(',', $array);
#2
3
Add this line: $files= implode(',', $value);
添加以下行:$ files = implode(',',$ value);