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

时间:2012-02-13 11:22:49

标签: php

如何切掉第一个值?

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


    }

4 个答案:

答案 0 :(得分:1)

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

// use your loop

答案 1 :(得分: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>";

}

答案 2 :(得分: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>";


    }

答案 3 :(得分:-1)

if(key($ dataArray)=== 0))继续;但这只有在您不手动指定密钥时才有效。

相关问题