2012-02-13 39 views
-4

如何切割第一個值?從數組中的第二個值開始的foreach函數

foreach ($dataArray ['simpleforecast']['forecastday'] as $arr) { 


     $html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />"; 
     $html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />"; 
     $html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>"; 
     $html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>"; 
     $html .= "</td>"; 


    } 

回答

1
$first = array_shift($dataArray ['simpleforecast']['forecastday']); 

// use your loop 
0

快速和骯髒的:

$first = true; 
foreach ($dataArray['simpleforecast']['forecastday'] as $arr) { 
    if ($first) { $first = !$first; continue; } 

    $html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />"; 
    $html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />"; 
    $html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>"; 
    $html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>"; 
    $html .= "</td>"; 

} 
0
$i = 1; 
foreach ($dataArray ['simpleforecast']['forecastday'] as $arr) { 

     if($i==1) 
     { 
     $i++; 
     continue; 
     } 
     $html .= "<td align='center' style='font-size:10px; font-weight:bold' >" . substr($arr['date']['weekday'], 0,3) . "<br />"; 
     $html .= "<img style='border-radius:15px' src='http://icons-pe.wxug.com/i/c/a/" . $arr['icon'] . ".gif' border=0 /><br />"; 
     $html .= "<font style='font-weight:bold' color='#555'>" . $arr['high'][$tempScale] . $tempUnit . " </font>"; 
     $html .= "<font style='font-weight:normal' color='grey'>" . $arr['low'][$tempScale] . $tempUnit . "</font>"; 
     $html .= "</td>"; 


    } 
+0

感謝您的快速幫助 – 2012-02-13 11:51:19

-1

如果(鍵($ dataArray中)=== 0))繼續;但是這隻有在你沒有手動指定密鑰的情況下才有效。

相關問題