-1
我有一個小問題如何將以下代碼轉換爲whileloop,我知道如何創建whileloop但使用simpleXML代碼似乎引起了我當然。SimpleXML節點屬性循環
我的代碼讓我得到第一個或最後一個屬性,但我需要所有這些屬性。
任何一個可以幫助
<?php foreach (current($xml->xpath('/*/gig[last()]'))->attributes() as $attr) {}?>
我有一個小問題如何將以下代碼轉換爲whileloop,我知道如何創建whileloop但使用simpleXML代碼似乎引起了我當然。SimpleXML節點屬性循環
我的代碼讓我得到第一個或最後一個屬性,但我需要所有這些屬性。
任何一個可以幫助
<?php foreach (current($xml->xpath('/*/gig[last()]'))->attributes() as $attr) {}?>
我不知道你的實際代碼是什麼樣子,但這個工程:
$xml = simplexml_load_string(
'<gigs>
<gig a="1" b="2"/>
</gigs>'
);
foreach (current($xml->xpath('/*/gig[last()]'))->attributes() as $k => $v)
{
var_dump($k,$v);
}
每個屬性列出,無論是它的名字( $ k)及其價值($ v)
while ($cur = each(...))