将数组数据合并为一个变量[重复]

This question already has an answer here:

I have foreaching array:

$arr = array(2,3,4);
$copy = $arr;
foreach ($arr as $val) {
    echo $val;
    if (next($copy )) {
        echo ','; // Add comma for all elements instead of last
    }
}

and the result is:

2,3,4

How to create a variable with value is above result, so it will looks like $var = '2,3,4' ?

</div>
 foreach ($arr as $val) {
     $copy += $val;
}

Use implode():

$arr = [2,3,4];
$var = implode($arr, ',');
var_dump( $var );

Output:

string(5) "2,3,4"