I have an array with nested arrays inside that I need to convert into a string with a given format.
This is for a PHP website. I get the information from a database, it comes as an array, and I need to pass it to charts.js so that I can plot it.
This is the varDump I get when I query the DB:
array(4) { [0]=> array(2) { ["date"]=> string(19) "2019-05-19 00:00:00" ["price"]=> string(3) "120" } [1]=> array(2) { ["date"]=> string(19) "2019-05-12 00:00:00" ["price"]=> string(3) "100" } [2]=> array(2) { ["date"]=> string(19) "2019-05-05 00:00:00" ["price"]=> string(3) "120" } [3]=> array(2) { ["date"]=> string(19) "2019-04-28 00:00:00" ["price"]=> string(3) "110" } }
This is what I would need as a result in a text string:
data: [{
x: 2019-05-19 00:00:00,
y: 120
}, {
t: 2019-05-12 00:00:00,
y: 100
}, {
t: 2019-05-05 00:00:00,
y: 120
}, {
t: 2019-04-28 00:00:00,
y: 110
}]