Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在for循环中增加变量,以便从“$filename”变成“$filename1”,然后变成$filename2?
$filename = false; $filename1 = false; $filename2 = false; for ($i = null; $i <=2; $i++){ $filename = $this->blabla; }
使用变量变量:
${"filename".$i} = $this->blabla;
文档
尝试,类似:
for($i=0; $i<3; $i++){ $ii = $i === 0 ? '' : $i; ${"filename$ii"} = $this->blabla; }
或者
for($i=0; $i<3; $i++){ $ii = $i === 0 ? '' : $i; $f = "filename$ii"; $$f = $this->blabla; }