public function to_array() { // Return an array representation of the record. $d = array(); if (!empty($this->valid_since)) { $d['@valid_since'] = PiplApi_Utils::piplapi_datetime_to_str($this->valid_since); } if (!empty($this->match)) { $d['@match'] = $this->match; } if (!empty($this->category)) { $d['@category'] = $this->category; } if (!empty($this->origin_url)) { $d['@origin_url'] = $this->origin_url; } if (!empty($this->sponsored)) { $d['@sponsored'] = $this->sponsored; } if (!empty($this->domain)) { $d['@domain'] = $this->domain; } if (!empty($this->person_id)) { $d['@person_id'] = $this->person_id; } if (!empty($this->id)) { $d['@source_id'] = $this->id; } if (!empty($this->premium)) { $d['@premium'] = $this->premium; } return array_merge($d, $this->fields_to_array()); }
public function to_array() { // Return a dict representation of the field. $d = array(); if (!empty($this->valid_since)) { $d['@valid_since'] = PiplApi_Utils::piplapi_datetime_to_str($this->valid_since); } $newattr = array_map(array($this, "internal_mapcb_attrsarr"), $this->attributes); $newchild = array_map(array($this, "internal_mapcb_childrenarr"), $this->children); // $newattr and $newchild are multidimensionals- this is used to iterate over them // we first merge the two arrays and then create an iterator that flattens them $it = new RecursiveIteratorIterator(new RecursiveArrayIterator(array_merge($newattr, $newchild))); foreach ($it as $key => $prefix) { if (array_key_exists($key, $this->internal_params)) { $value = $this->internal_params[$key]; if (isset($value) && is_object($value) && method_exists($value, 'to_array')) { $value = $value->to_array(); } if (isset($value)) { $d[$prefix . $key] = $value; } } } return $d; }