I have a code in PHP to works with XML:
$data_measuranment = file_get_contents($value, false, $context);
$xml=simplexml_load_string($data_measuranment);
$json = json_encode($xml);
$array[] = json_decode($json,TRUE);
The values of my array ($array[]) depend on the time:
[1] => Array
(
[@attributes] => Array
(
[end] => 1520439534044
[start] => 1520439300000
[step] => 300000
)
[columns] => Array
(
[values] => Array
(
[0] => NaN
[1] => NaN
)
)
[timestamps] => Array
(
[0] => 1520439300000
[1] => 1520439600000
)
)
...
If I execute the code some seconds ago. My array works:
[1] => Array
(
[@attributes] => Array
(
[end] => 1520439565293
[start] => 1520439300000
[step] => 300000
)
[columns] => Array
(
[values] => Array
(
[0] => 12
[1] => NaN
)
)
[timestamps] => Array
(
[0] => 1520439300000
[1] => 1520439600000
)
)
...
The only value important for my is array[key][columns][values][0]=12
So, I need a code to wait some seconds and execute again the pull for the API and finish when the value array[1][columns][values][0] is different to NaN. I tried to do that with this code but not works:
do
{
foreach ($array as $valor)
{
$term= $valor['columns']['values']['0'] ;
if ($term === 'NaN')
{
unset($array);
sleep(10);
$data_measuranment = file_get_contents($value, false, $context);
$xml=simplexml_load_string($data_measuranment);
$json = json_encode($xml);
$array[] = json_decode($json,TRUE);
}
}
}while (isset($array))
I need this: When the foreach read the value "$valor['columns']['values']['0']" and check is NaN. The code wait 10 seconds and retreive new array with file_get_contents, then check the condition again. If all values of $valor['columns']['values']['0'] are different of NaN continue the script.
Thank you.