PHP for loop is very similar to a while loop in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line.
The?foreach loop?is mainly used for looping through the values of an array. It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array.
2019-03-16
foreach 可用于關(guān)聯(lián)和索引數(shù)組,它是自動(dòng)遞增訪問指針(從開始到結(jié)束);
for則用于自定義地訪問;(包括start,end,step)
引用 w3school:
PHP for loop is very similar to a while loop in that it continues to process a block of code until a statement becomes false, and everything is defined in a single line.
The?foreach loop?is mainly used for looping through the values of an array. It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array.