douxi1738 2015-06-03 09:41
浏览 25

如果不是,虽然声明是真的。 (PHP)

When I Do an IF Statement using PHP while checking values from an XML File, It thinks that the statement is not true although it is..

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<TacviewDebriefing Version="1.2.6">
    <Mission>
        <Title>TAPE0003</Title>
        <MissionTime>2015-06-03T00:00:00Z</MissionTime>
        <Duration>32890.02</Duration>
        <MainAircraftID>59</MainAircraftID>
    </Mission>
    <Events>
        <Event>
            <Time>32224.76</Time>
            <PrimaryObject ID="59">
                <Type>Aircraft</Type>
                <Name>F-16C Fighting Falcon</Name>
                <Pilot>Viper</Pilot>
                <Coalition>ROK/Shark</Coalition>
            </PrimaryObject>
            <Action>HasTakeOff</Action>
            <Airport ID="ICAO:LLHS">
                <Name>Hatzor AFB</Name>
            </Airport>
        </Event>
    </Events>
</TacviewDebriefing>

and that the sample of my code:

$xml = simplexml_load_file($filedir) or die("Error: Could not open file<br>");
    if(isset($xml->Mission)){
        foreach($xml->Events->Event as $value){
            $num++;
            if($xml->Mission->MainAircraftID === $value->PrimaryObject['ID']{
                echo $value->Action;
            }   
        }
    }

P.S: If i try to echo $value->PrimaryObject['ID'];
and echo $xml->Mission->MainAircraftID; (Inside the foreach loop)
it prints 59 and 59...

  • 写回答

1条回答 默认 最新

  • douyin2883 2015-06-03 09:56
    关注

    Eventually i took Mark Baker's advise and made the if statement like this: if((string)$value->PrimaryObject['ID'] === (string) $xml->Mission->MainAircraftID) Thank you guys.

    评论

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真