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

'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进阶篇
  • 参与学习       181944    人
  • 解答问题       2668    个

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

进入课程

'foreach'与'for'的区别?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号