I’m looping through a set of data and pulling the following results:
$str[] = $id . '~' . $desc;
At the end of the loop I put these together:
$txt_str = implode('^',$str);
echo $txt_str;
1~one^2~two^3~three
Out of curiosity, could I get the same result by directly processing an array?
$arr[] = array('id'=$id, 'desc'=>$desc);
So something like:
$txt_str = makemeasammich('~', '^', $arr);
echo $txt_str;
1~one^2~two^3~three
Is there a native PHP function that has this capability?
There is no such native PHP function.
Use
implode()andarray_map()(with anonymous function):