public function testIsAssociative() { $this->assertTrue(ArrayHelpers::isAssociative(array('foo' => 'bar', 'baz'))); $this->assertFalse(ArrayHelpers::isAssociative(array('foo', 'bar'))); }
/** * @param DomDocument $document * @param string $elementName * @param mixed $content array or string */ private static function _toElement($document, $elementName, $content) { $element = $document->createElement($elementName); if (is_array($content)) { if (isset($content['@attributes'])) { foreach ($content['@attributes'] as $k => $v) { $element->setAttribute($k, $v); } unset($content['@attributes']); } if (isset($content['@value'])) { $element->appendChild($document->createTextNode(self::_stringify($content['@value']))); unset($content['@value']); } else { foreach ($content as $k => $v) { if (is_array($v) && !ArrayHelpers::isAssociative($v)) { // Repeating element foreach ($v as $childContent) { $element->appendChild(self::_toElement($document, $k, $childContent)); } } else { $element->appendChild(self::_toElement($document, $k, $v)); } } } } else { $element->appendChild($document->createTextNode(self::_stringify($content))); } return $element; }