簡體   English   中英

php5腳本升級-foreach內部foreach

[英]php5 script upgrade - foreach inside foreach

我正在嘗試將腳本從PHP4升級到PHP5,而foreach遇到問題。 我在網上看了一下,卻找不到適合我的腳本的任何內容。

基本上,問題在於第9行的$filmid和第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>";

}

您在最后一個foreach循環中缺少}

這里確實沒有足夠的信息可以處理,但是我猜想是作為數組訪問的var實際上是對象。

因此,我建議更改:

$event['titleID']

進入

$event->titleID

如果可行,那就太好了。 如果它不起作用,則需要通過提供var_dump($thisweeksxml)print_r($thisweeksxml)的輸出,向我們展示有關$thisweeksxml更多信息。 (將其編輯為原始問題)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM