I am using a foreach statement to echo the data I have out to a jquery chart (flotchart). The form needs to be {"label", data}, {"label", data}, {"label", data}
But my foreach statement adds a comma after every row including the last row which I can’t have a comma because it is breaking the script.
I am currently using
foreach ($bycountry as $country) {print
'{ label: "' . $country['origincountry'] . '", data: ' . $country['countrytotal']. ' }, ';
}
This gives me: {"label", data}, {"label", data}, {"label", data},
I need no comma on the last row
Have you tried just
json_encodeit?You’ll need to reorganize your array a bit, but it is a much cleaner approach.
Another way is to use
implode, however you’ll need to reorganize your array anyway: