首页 > 解决方案 > 左大括号后的分号有什么作用

问题描述

我很难找出这个分号的目的是什么for (;。我在网上的搜索只带来了不相关的结果。有人可以解释一下吗?

for (; $this->foo <=10; $this->foo++) {}

标签: phpfor-loop

解决方案


这基本上跳过了迭代器变量的初始化。通常你会输入这样的内容:

for ($i = 0; $this->foo <= 10; $i++) {}

但是,在您的示例中,您访问的对象$this只是将 foo 累加了 1;


推荐阅读