我试图将Judy改编成我的代码,使用它几乎就像传统的php数组一样,但我在尝试访问多维数组时遇到了不好的时间。每当我尝试打印嵌套键值时,我都会得到一个NULL。
我的代码:
/**
* 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;
}