Hi all!
I have a problem with a PHP code I'm writing. First of all: I have zero skills in PHP, I'm a Programmer Analyst but all I've done is related to Cobol, DDBB and the like. So I am less than a newbie here, and I'm just writing code after searching things in Google. I just have no time to make the program work, so I can't study as much as I want!
What do I need? Very simple: I need two arrays, one with Hours and the other one with Prices, so I can make a graph (with JpGraph) just by telling "this array is the X axis, and this other array is the Y axis".
So I have this variable, $array_indicators, as a JSON decoded. And I'm able to get the Hours and Prices stored in $array_indicators. And now I want to declare a new array ($array_hprice), with a sequential numeric index, with two values for each entry: Hour and Price.
This is my code:
$i = 0;
if($array_indicators)
{
foreach ($array_indicators as $valor)
{
// Getting HOUR in the format I need.
$hour = date ('H:i:s', strtotime ( $valor['datetime']) );
// Getting PRICE.
$price = $valor['value'];
// Building array.
$array_hprice[$i] = [$hour, $price];
// Testing result.
echo "Hour: ".$array_hprice[$i][0].", Price: ".$array_hprice[$i][1]."<br>\n";
$i++;
}
}
I tried this code in my house, with a local Apache server and PHP 5.4, and worked perfectly. After this, I was able to create the graph using this two arrays:
array_column($array_hprice, 0);
array_column($array_hprice, 1);
The first one for Hours, the second one for Prices.
Now, return to real world. I put my code in my real server, here in my working place, with PHP 7.0 installed... and it didn't work!! Specifically, this is the part don't working:
$array_hprice[$i] = [$hour, $price];
Apparently, now I can´t declare my array that way. And I don't know why, and I don't know how to do it.
So, please, could anyone help me?? I know my PHP code sure is atrocious... But I don't know what's the best way to get what I need now! Obviously, I could build two separate arrays: one for Hours, and the other for Prices; but that's something I'd like to avoid, if possible...
Real question, then: What's best way to do what I need to do?
Thank you very much!!