为了账号安全,请及时绑定邮箱和手机立即绑定

'foreach'与'for'的区别?

'foreach'与'for'的区别?


正在回答

1 回答

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.

1 回复 有任何疑惑可以回复我~
#1

skjaao 提问者

谢谢你的解答。
2019-03-16 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
PHP进阶篇
  • 参与学习       181827    人
  • 解答问题       2577    个

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

进入课程

'foreach'与'for'的区别?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信