is there a way in PHP to restart a loop in a foreach, or change the test value in a switch?

孤街醉人 提交于 2019-12-05 19:32:55

Not with a foreach, but with more manual array iteration:

while (list($key, $value) = each($array)) {
    if (...) {
        reset($array); // start again
    }
}

http://php.net/each
http://php.net/reset

It seems like a simple fall through would do the trick though:

switch ($storage_location) {
    case 'cookie':
        if (!headers_sent()) {
            set_cookie();
            break;
        }

        // falls through to next case

    case 'session':
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!