1
I have a file named json data. structured as follows:
{
"price_usd": [
[
1588464000000,
10,
8
],
[
1588464000000,
10,
8
],
[
1588464000000,
10,
8
],
[
1588464000000,
3,
2.8
],
[
1588550400000,
3,
2.8
],
[
1588550400000,
3,
2.8
]
]
}
The first variable represents the date of a sale, the second variable the sale price of the product, the third variable is the purchase price.
I would like to define in PHP strings, the following three variables with the file data in example, where the dates will be grouped and the values summed:
$data = "1588464000000, 1588550400000";
$venda = "33, 6";
$compra = "26.8, 5,6";
To extract the data from the file I use:
$JSON = file_get_contents('dados.json');
I would like to obtain the sums of the values (purchase price and sale price) grouped by the dates, that is, add up everything that was sold "yesterday" and "today" for example.
As far as he wrote "...the third variable is the purchase price." it is clear, from the moment he wrote "... Would you like to set in PHP strings..." onwards is not understandable. What do you want to do? Put
$data
,venda
and$compra
in an array within your JSON file?– Augusto Vasques
@Augustovasques would like to get the sums of the values (purchase price and sale price) grouped by the dates, ie, add up everything that was sold "yesterday" and "today" for example.
– talnun
talun, put in the question that you explained in the comments. And put an example of how you tried to solve the problem so I can give you guidance.
– Augusto Vasques
as soon as I can adapt something that brings me some results I update with the examples, sorry but I haven’t been able to yet. I am trying to adapt these answers https://answall.com/a/294046/90997, https://answall.com/a/1745/90997 and https://answall.com/a/117985/90997
– talnun