简体   繁体   English

PHP XPath 2.0 获得最大值,最大值

[英]PHP XPath 2.0 get highest value with max

I´ve a given XML structur:我有一个给定的 XML 结构:

<?xml version="1.0" encoding="utf-8"?>
<phonebooks>
    <phonebook name="xxx" owner="1">
        <contact>
            ...
            <mod_time>1452420868</mod_time>
            <uniqueid>2026447</uniqueid>
        </contact>
        <contact>
        ...
        </contact>
    </phonebook>
</phonebooks>

And I need the highest value (latest timestamp) from <mod_time>我需要<mod_time>的最大值(最新时间戳)

xpathtester said, that max(//mod_time) will be allright. xpathtester说, max(//mod_time)就可以了。

So I tried in my script:所以我在我的脚本中尝试了:

$modTime = $phonebook->xpath(max('//mod_time'));

which delivered me the warning这给了我警告

max(): When only one parameter is given, it must be an array max():只给一个参数时,必须是数组

Any quick help around?有什么快速的帮助吗?

Thx谢谢

Just move the quotes to use the fn:max function and not the PHP function:只需移动引号以使用fn:max function 而不是 PHP function:

$modTime = $phonebook->xpath('max(//mod_time)');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM