【问题标题】:Simple xml php array wildcard简单的 xml php 数组通配符
【发布时间】:2012-05-30 20:08:51
【问题描述】:

您能否告知 php.ini 中简单 xml 的数组通配符是什么?我想从数组的第二部分获得通配符响应。它仅在错误填充有数字时才起作用,通配符是什么,因此它将带回 stuff 数组 0 中的所有错误。

例子

$xml->Test->Account->Information->Stuff[0]->Next->Next->Error[]['Duration'];

【问题讨论】:

    标签: php xml arrays simplexml


    【解决方案1】:

    类似

    $results = array();
    foreach ($xml->Test->Account->Information->Stuff[0]->Next->Next->Error as $error) {
        $results[] = $error['Duration'];
    }
    

    【讨论】:

    • 嗨。我的意思是 Error[] 通常是 Error[1] 或为数组选择的任何数字。我想要 [] 的通配符值,因为我已经尝试过 * 但这似乎不起作用。
    • 所以我正在查看 Stuff[0] 中的第一条记录,然后想要获取其中发生的所有错误,所以我没有 Error[0]、Error[1] 等,而是只想在 [] 中放一个通配符。
    • 这就是我的代码打算提供的行为。我知道的唯一其他方法是使用$xml->xpath('//Test/Account/Information/Stuff[1]/Next/Next/Error[@Duration]')
    猜你喜欢
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多