多维Judy数组

时间:2016-10-23 12:09:50

标签: php arrays json judy-array

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

  1. 我如何迭代我的结果?
  2. 如何将此结构编码为json?每当我尝试时,我都会得到一个空的支撑“{}”
  3. 我的代码:

    /**
     * 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;
    
    }
    

0 个答案:

没有答案