Foreach函数从数组中的第二个值开始


Foreach function to start from the 2nd value in the array

如何将第一个值切片?

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>";

    }
$first = array_shift($dataArray ['simpleforecast']['forecastday']);
// use your loop

快速且肮脏:

$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>";
}
$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>";

    }

if(key($dataArray)===0)continue;但是,只有在不手动指定关键点的情况下,这才会起作用。