在PHP中使用子元素(元素)从平面数组创建嵌套数组
是否可以转换元素数组:在PHP中使用子元素(元素)从平面数组创建嵌套数组,php,arrays,Php,Arrays,是否可以转换元素数组: Array ( [@attributes] => Array ( [targetNamespace] => http://example.com ) [element] => Array ( [0] => Array ( [@attributes] => Array (
Array
(
[@attributes] => Array
(
[targetNamespace] => http://example.com
)
[element] => Array
(
[0] => Array
(
[@attributes] => Array
(
[name] => title
[type] => string
)
)
[1] => Array
(
[@attributes] => Array
(
[name] => author
[type] => string
)
)
[2] => Array
(
[@attributes] => Array
(
[name] => book
)
[complexType] => Array
(
[sequence] => Array
(
[element] => Array
(
[0] => Array
(
[@attributes] => Array
(
[ref] => namespace:title
)
)
[1] => Array
(
[@attributes] => Array
(
[ref] => namespace:author
)
)
)
)
)
)
)
)
在这种情况下,我们可以从“element”键开始
根据子元素的名称放入嵌套数组:
Array
(
[book] => Array
(
[element] => Array
(
[0] => Array
(
[@attributes] => Array
(
[ref] => namespace:title
[name] => title
)
)
[1] => Array
(
[@attributes] => Array
(
[ref] => namespace:author
[name] => author
)
)
)
)
)
这是xsd文件的表示形式,我正在尝试在模式中查找rootElement,那么您已经有权访问xsd文件了吗?你所说的根元素是什么意思?可能一个简单元素用于多个复杂元素中。在这种情况下,您将如何定义“root”?您能告诉我们所需的输出吗?是的,我可以访问XSD文件,这是我唯一拥有的。定义根很简单:前两个元素(title、author)在模式中描述,而“book”元素包含对这些元素的引用,所以“book”是我的根。正确构造的模式应该提供这样的信息。所需的输出列在“基于子元素名称的嵌套数组:”下面。只要“book”元素是数组中的“top”键,它就可以是任何可能的输出。