dongpa3109 2017-09-28 13:02
浏览 234
已采纳

如何获取此STRING值而不是ID

Good day. Hope someone can help me solve this problem of mine in getting the actual String value instead of id.

<Pull_ListSpecProp_RS>
    <Property>
        <Amenities>
              <Amenity Count="1">2</Amenity>
              <Amenity Count="1">4</Amenity>
              <Amenity Count="1">6</Amenity>
              <Amenity Count="2">19</Amenity>
              <Amenity Count="1">74</Amenity>
              <Amenity Count="1">115</Amenity>
              <Amenity Count="1">124</Amenity>
              <Amenity Count="1">125</Amenity>
              <Amenity Count="1">140</Amenity>
              <Amenity Count="1">174</Amenity>
              <Amenity Count="1">180</Amenity>
              <Amenity Count="1">187</Amenity>
              <Amenity Count="1">395</Amenity>
              <Amenity Count="1">589</Amenity>
              <Amenity Count="1">792</Amenity>
              <Amenity Count="1">798</Amenity>
        </Amenities>
    <Property>    
</Pull_ListSpecProp_RS>

**

<Pull_ListAmenities_RS>
    <Amenities>
       <Amenity AmenityID="2">Cookware &amp; Kitchen Utensils</Amenity>
       <Amenity AmenityID="3">Crockery &amp; Cutlery</Amenity>
       <Amenity AmenityID="4">Iron &amp; Ironing Board</Amenity>
       <Amenity AmenityID="5">Drying Rack</Amenity>
       <Amenity AmenityID="6">Hair Dryer</Amenity>
       <Amenity AmenityID="7">Bed Linen &amp; Towels</Amenity>
       <Amenity AmenityID="8">Toiletries</Amenity>
    </Amenities>
</Pull_ListAmenities_RS>

if (Amenity == AmenityID) if True, I want the return value to be the string value of the 2nd Amenity response.

example Amenity= 2 and AmenityID= 2 the return value will be

if(Amenity == AmenityID){
  echo Amenity;
}

//Output Cookware &amp; Kitchen Utensils

This is my current code

foreach($Pull_ListSpecProp_RQ->Property->Amenities->Amenity as $AmenityID){ //This foreach is to get all the available Amenity of a specific/selected room
   foreach ($Pull_ListAmenities_RQ->Amenities->Amenity as $Amenity) { //This for each is to get all the List of amenities.
     //echo "ID: ".$Amenity['AmenityID']."<br/>";
     if ($AmenityID == $Amenity['AmenityID']) {
       echo "ID: ".$Amenity."<br/>";
     }
   }
}

Hope my question and explanation is understandable. Sorry for this dumb question of mine. im not a good programmer, yet :).

  • 写回答

1条回答 默认 最新

  • dongtu7205 2017-09-28 13:40
    关注

    The variables $AmenityID and $Amenityare of type SimpleXMLElement.

    These have a method __toString which will return the string content.

    Maybe you can compare the string content of $AmenityID with the AmenityID attribute of $Amenity.

    For example:

    foreach($Pull_ListSpecProp_RQ->Property->Amenities->Amenity as $AmenityID){ 
        foreach ($Pull_ListAmenities_RQ->Amenities->Amenity as $Amenity) {
            if ($AmenityID->__toString() === $Amenity->attributes()->AmenityID->__toString()) {
                echo $Amenity->__toString() . "<br>";
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度