An array of \GeoIp2\Record\Subdivision * objects representing the country * subdivisions for the requested IP * address. The number and type of * subdivisions varies by country, * but a subdivision is typically a * state, province, county, etc. * Subdivisions are ordered from most * general (largest) to most specific * (smallest). If the response did * not contain any subdivisions, this * method returns an empty array. */ public readonly array $subdivisions; /** * @ignore * * @param array $raw * @param list $locales */ public function __construct(array $raw, array $locales = ['en']) { parent::__construct($raw, $locales); $this->city = new CityRecord($raw['city'] ?? [], $locales); $this->location = new Location($raw['location'] ?? []); $this->postal = new Postal($raw['postal'] ?? []); if (empty($raw['subdivisions'])) { $this->subdivisions = []; $this->mostSpecificSubdivision = new Subdivision([], $locales); return; } $subdivisions = []; foreach ($raw['subdivisions'] as $sub) { $subdivisions[] = new Subdivision($sub, $locales) ; } $this->mostSpecificSubdivision = $subdivisions[\count($subdivisions) - 1]; $this->subdivisions = $subdivisions; } /** * @return array|null */ public function jsonSerialize(): ?array { $js = parent::jsonSerialize(); $city = $this->city->jsonSerialize(); if (!empty($city)) { $js['city'] = $city; } $location = $this->location->jsonSerialize(); if (!empty($location)) { $js['location'] = $location; } $postal = $this->postal->jsonSerialize(); if (!empty($postal)) { $js['postal'] = $postal; } $subdivisions = []; foreach ($this->subdivisions as $sub) { $subdivisions[] = $sub->jsonSerialize(); } if (!empty($subdivisions)) { $js['subdivisions'] = $subdivisions; } return $js; } }