Imbo\Http\Response\Formatter\XML::formatArray PHP Метод

formatArray() приватный Метод

Format a nested dataset
private formatArray ( array $data ) : string
$data array A nested array
Результат string
    private function formatArray(array $data)
    {
        $xml = '';
        if (isset($data[0])) {
            $xml .= '<list>';
            foreach ($data as $value) {
                $xml .= '<value>';
                if (is_array($value)) {
                    $xml .= $this->formatArray($value);
                } else {
                    $xml .= $this->formatValue($value);
                }
                $xml .= '</value>';
            }
            $xml .= '</list>';
        } else {
            foreach ($data as $key => $value) {
                $xml .= '<' . $key . '>';
                if (is_array($value)) {
                    $xml .= $this->formatArray($value);
                } else {
                    $xml .= $this->formatValue($value);
                }
                $xml .= '</' . $key . '>';
            }
        }
        return $xml;
    }