Im trying to adapt Judy into my code using it almost as a conventional php array but i am having a bad time trying to access the multidimensional array. Everytime i try to print a nested key value i get a NULL.
- how can i iterate through my results?
- how can i encode this structure into a json? Everytime i try, i get a empty bracets "{}"
My code:
/**
* This method parses the content of XML body
* Array of objects to spare more memory usage
* @param $xml object SimpleXml Object
* @param $timeRequest array this second param brings the time_request value along with the url
*/
private function parseXmlContent($xml, $timeRequest)
{
$counter = 0;
$forecast = new \Judy(Judy::INT_TO_MIXED);
foreach ($xml->point as $key => $value):
$forecast[$counter] = $this->initJudy($value, $timeRequest, count($value);
$counter++;
endforeach;
$this->sucess++;
$this->results[$this->results->nextEmpty(0)] = $forecast;
}
private function initJudy($value, $timeRequest, $length)
{
$judy = new \Judy(Judy::STRING_TO_MIXED);
$judy['timestamp'] = (string)$value->data[0];
$judy['time_request'] = $timeRequest[0]->time_request;
$judy['latitude'] = (string)$value->data[1];
$judy['longitude'] = (string)$value->data[2];
$j = 0;
for ($i = 3; $i < $length; $i++) {
$attribute = $this->variables[$j];
$judy[$attribute] = (string)$value->data[$i];
$j++;
}
return $judy;
}