2012-02-13 13 views
-4

最初の値をどのようにスライスすることができますか?配列の2番目の値から開始する関数の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

ご協力ありがとうございます –

-1

場合(キー($ dataArray)=== 0))続けます。しかし、これは手動でキーを指定しない場合にのみ機能します。

関連する問題