'foreach'与'for'的区别?

来源:1-7 PHP数组之关联数组初始化

skjaao

2019-03-16 10:54

'foreach'与'for'的区别?


写回答 关注

1回答

  • 啊啊哈哈0
    2019-03-16 11:58:19

    foreach 可用于关联和索引数组,它是自动递增访问指针(从开始到结束);

    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.

    skjaao

    谢谢你的解答。

    2019-03-16 15:27:19

    共 1 条回复 >

PHP进阶篇

轻松学习PHP中级课程,进行全面了解,用PHP快速开发网站程序

181835 学习 · 2577 问题

查看课程

相似问题