PHP တွင် XML တဂ်များ၏ အုပ်စု attributes များ

ယခု attributes များပါသော တဂ်များစွာရှိသည်ဆိုပါစို့

test.xml<root>
  <tag attr="val1">text1</tag>
  <tag attr="val2">text2</tag>
  <tag attr="val3">text3</tag>
</root>

ထိုတဂ်များ၏ စာသားများကိုရယူကြပါစို့။

index.php<?php
  foreach ($xml->tag as $tag) {
    echo $tag; // 'text1', 'text2', 'text3'
  }
?>

ယခု - attributes များ၏တန်ဖိုးများကိုရယူကြပါစို့။

index.php<?php
  foreach ($xml->tag as $tag) {
    echo $tag['attr']; // 'val1', 'val2', 'val3'
  }
?>
Задание 1

အောက်ပါ XML ကိုပေးထားသည်။

html<root>
  <product cost="100" amount="3">
    prod1
  </product>
  <product cost="200" amount="4">
    prod2
  </product>
  <product cost="300" amount="5">
    prod3
  </product>
</root>

ထုတ်ကုန်တစ်ခုစီ၏အမည်၊ စျေးနှုန်းနှင့် အရေအတွက်ကိုစခရင်ပေါ်တွင်ဖော်ပြပါ။