我正在尝试将脚本从 PHP4 升级到 PHP5,但我遇到了 foreach 问题。我在网上查看过,但找不到任何适合我的脚本的东西。
基本上,问题在于无法识别$filmid
第 9 行和第 13 行,并且数组返回空。$event['venueID']
我可以通过分配值来使其工作,$filmid
但$event['venueID']
显然这完全违背了这一点。
所以基本上,我怎样才能重写这些让我的脚本工作?if($event['titleID'] == $filmid){ 和 if($venue['venueID'] == $event['venueID']){
这是我正在使用的数据:
<listing>
<venueList>
<venue venueID="vxappfil">
</venue>
</venueList>
<titleList>
<title titleID="txgrewhi3">
<titleName>The Great White Silence</titleName>
</title>
</titleList>
<eventList>
<event titleID="txgrewhi3" venueID="vxappfil">
<startDate>03/08/2012</startDate>
<endDate>09/08/2012</endDate>
<times>Sun 19:00</times>
</event>
</eventList>
</listing>
以下是代码:
foreach ($thisweeksxml->titleList->title as $title) {
$filmid = $title['titleID'];
......
$thiweekscinemasnamesarray = array();
foreach ($thisweeksxml->eventList->event as $event) {
if($event['titleID'] == $filmid ){
foreach ($thisweeksxml->venueList->venue as $venue) {
if($venue['venueID'] == $event['venueID']){
$cityname = strtolower(str_replace ($removeChars, "", $venue->venueAddress->town));
$venuname = strtolower(str_replace ($removeChars, "", $venue->venueName));
$thiweekscinemasnamesarray[] = ("- <a href='/cinema/".$cityname."-".$venuname.".html'><font size='-2' style='line-height:15pt'>".$venue->venueAddress->town.", ".$venue->venueName."</font></a>");
}
}
}
}
sort($thiweekscinemasnamesarray);
foreach($thiweekscinemasnamesarray as $lastweek){
$bodycontent .="".$lastweek."<br>";
}