childNodes; $children_count = count($children); for ($i = 0; $i < $children_count; ++$i) { $child = $children[$i]; if (in_array($child->tagName, self::$direct_inputs)) { self::fillDirectInput($child, array_shift($data) ?? ''); continue; //$child->setAttribute('value', array_shift($data) ?? 'empty'); } if ($child->tagName === 'select') { self::fillSelectElement($child, array_shift($data) ?? ''); continue; } if ($recursive) { self::traverse($child, $data); } } } private static function fillDirectInput($node, $value) { if ($value === '') { return; } $node->setAttribute('value', $value); } private static function fillSelectElement($node, $value) { if ($value === '') { return; } $children = $node->childNodes; foreach ($children as $child) { if (($child->tagName === 'option') && ($child->getAttribute('value') === $value) ) { $child->setAttribute('selected', 'selected'); return; } } } }