xml - php simplexml get maximum value -


how possible highest existing guid value existing xml file (simplexml).

xml-structure example:

<xml blabla>  <blog name="">   <post>    <guid>3</guid>    <author></author>    <content>...</content>   </post>   <post>    <guid>1</guid>    <author></author>    <content>...</content>   </post>  </blog> 

i tried following ($xml simplexml object) max($xml->xpath(/blog/post/guid)); seems no array...

any suggestions? there way handle per xpath? google search wasn't successful.

you use array_map('intval'... feed max() "understands".

<?php $xml = getdoc(); $ns = $xml->xpath('//blog/post/guid'); $ns = array_map('intval', $ns); echo max($ns);  function getdoc() {     return new simplexmlelement( <<< eox <xml>  <blog name="">   <post>    <guid>3</guid>    <author></author>    <content>...</content>   </post>   <post>    <guid>1</guid>    <author></author>    <content>...</content>   </post>   <post>    <guid>99</guid>    <author></author>    <content>...</content>   </post>   <post>    <guid>47</guid>    <author></author>    <content>...</content>   </post>  </blog> </xml> eox     ); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -