get previous array values in foreach

后端 未结 7 1432
死守一世寂寞
死守一世寂寞 2021-02-01 23:04

My array :

$arr = array(\"jan\",\"feb\",\"mar\",\"apr\",\"mei\",\"jun\",\"jul\",\"agu\",\"sep\",\"okt\",\"nov\",\"des\");

then i do a foreach<

7条回答
  •  执笔经年
    2021-02-01 23:38

    A little more Dynamic

    $arr  = array(
        "jan",
        "feb",
        "mar",
        "apr",
        "mei",
        "jun",
        "jul",
        "agu",
        "sep",
        "okt",
        "nov",
        "des"
    );
    $arr2 = $arr;
    foreach ($arr as $k => $currVal) {
        unset($arr2[$k]);
        foreach ($arr2 as $k => $v) {
            $nextVal = $v;
    
            break;
        }
        echo "next val: " . $nextVal;
        echo "current val: " . $currVal;
    }
    

提交回复
热议问题