查看属性数组

Rya*_*yan 2 php arrays

我的代码非常简单,我只是这样:

$element = simplexml_load_string($data);
print_r($element);
Run Code Online (Sandbox Code Playgroud)

打印出:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [name] => addy'+r+'
            [id] => addy'+r+'
            [cols] => 45
            [rows] => 2
            [disabled] => disabled
        )

    [0] => '+url[r]+'
)
Run Code Online (Sandbox Code Playgroud)

无论如何我可以将属性数组放在for()循环中,这样我就可以在我的页面上随意添加键/值对了吗?

Phi*_*hil 5

使用该SimpleXMLElement::attributes()方法

$attributes = $element->attributes();
foreach ($attributes as $attr => $val) {
    // tada
}
Run Code Online (Sandbox Code Playgroud)