lundi 13 février 2017

Combine array data into one variable

Vote count: 0

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

asked 2 mins ago

Let's block ads! (Why?)



Combine array data into one variable

Aucun commentaire:

Enregistrer un commentaire