php – 将XML转换为关联数组

有没有办法使用Zend Framework和PHP将XML转换为数组?我见过人们使用SimpleXML来做这件事,但我想知道是否有通过Zend Framework的方法.

示例XML,我想转换为数组将是:

<library>
    <book>
        <authorFirst>Mark</authorFirst>
        <authorLast>Twain</authorLast>
        <title>The Innocents Abroad</title>
    </book>
    <book>
        <authorFirst>Charles</authorFirst>
        <authorLast>Dickens</authorLast>
        <title>Oliver Twist</title>
    </book>
</library>

转换后的数组将如下所示:

Array 
( 
        [0] => Array ( 
                      [authorFirst] => Mark 
                      [authorLast] => Twain
                      [title] => Innocents Abroad
                     )
        [1] => Array (
                      [authorFirst] => Charles 
                      [authorLast] => Dickens
                      [title] => Oliver Twist
                     )
)

解决方法:

如果你看看Zend_Config_XML的source code,你会看到他们使用SimpleXML来做几乎就是这样.我猜?他们建议你这样做.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...