作者: carlkyo 時間: 2017-3-17 17:40 標題: inner foreach loop
本帖最後由 carlkyo 於 2017-3-17 17:43 編輯
請問一下各位CHING
我想係$district->name加埋序號
用普通i++行唔到
many thanks
- $xmldata=simplexml_load_file("https://opendata.clp.com.hk/GetChargingSectionXML.aspx?lang=tc") or die("Error: Cannot create object");
- foreach($xmldata->areaList->area as $xml){
- echo '<hr/>';
- echo $xml->name.'<br/>';
- echo '<hr/>';
- foreach($xml->districtList->district as $district){
- echo $district->name.'<br/>';
- }
- }
作者: 7h1r733n 時間: 2017-3-17 17:48
- echo @++$t.". ".$district->name.'<br/>';
作者: 亞熙 時間: 2017-3-17 18:05
- foreach($xmldata->areaList->area as $xml){
- echo '<hr/>';
- echo $xml->name.'<br/>';
- echo '<hr/>';
- foreach($xml->districtList->district as $key=>$district){
- echo ($key+1) + ". " + $district->name.'<br/>';
- }
- }
咁樣又得唔得
- $i = 1;
- foreach($xmldata->areaList->area as $xml){
- echo '<hr/>';
- echo $xml->name.'<br/>';
- echo '<hr/>';
- foreach($xml->districtList->district as $district){
- echo $i + ". " +$district->name.'<br/>';
- $i++;
- }
- }
作者: carlkyo 時間: 2017-3-17 22:11
多謝兩位ching指教
many thanks
