I have a mysql fetch that is populating an associative array with columns from the DB.
One of the columns names is AMOUNT.
so it looks like this:
Array ( [0] => Array ( [ID] => 259 [YEARMONTH] => 201105 [AMOUNT] => 54 [VALUE] => 12 ) [1] => Array ( [ID] => 259 [YEARMONTH] => 201106 [AMOUNT] => 32 [VALUE] => 34 ) )
All I want to do is echo the AMOUNTs like this:
54,32
So that I don’t have trailing or heading commas.
Any suggestion for an elegant solution for this ?
Thanks !
Preconditions
$arraycontains the array for all rows.Code
If you are using PHP 5.3+, this following also works:
Courtesy of Mearlyn
More
implode– Takes an array and a delimiter and returns a string of ‘delimiter’ separated values of the array.