当我在检查XML文件中的值时使用PHP执行IF语句时,它认为该语句不是真的,尽管它是..
<?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>
我的代码示例:
$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:如果我试图回显$ value-&gt; PrimaryObject ['ID'];
和echo $ xml-&gt; Mission-&gt; MainAircraftID; (在foreach循环内)
它打印59和59 ...
答案 0 :(得分:0)
最终我接受了马克贝克的建议并做出了如下声明: if((string)$ value-&gt; PrimaryObject [&#39; ID&#39;] ===(字符串)$ xml-&gt; Mission-&gt; MainAircraftID) 谢谢你们。