I have a list of items from a database being parse in an array
Array
(
[0] => Array
(
[dToken] => 731fea87ea9dc61f16e93f1ad2b96
You're just about there.
$tokens = array();
foreach($result as $device){
$tokens[] = $device['dToken'];
}
echo implode(',', $tokens);
callback = function($row){
return $row['dToken'];
}
implode(",",array_map(callback,$result));
You could just build the string:
$cvsString = '';
$delimiter = '';
foreach($result as $device){
$cvsString.= $delimiter . $device['dToken'];
$delimiter = ',';
}
var_dump($cvsString);
Or you could first build in array:
$cvsArray = array();
foreach($result as $device){
$cvsArray[] = $device['dToken'];
}
var_dump(implode(',', $cvsArray));
To answer the question corresponding to the tile (transform an Array to a list with separator) use the implode
function. To generate a CSV I would google php CSV
, I'm sure there are already lots of function to do it.