Home >Backend Development >PHP Tutorial >请教一下php变量名字随参数变化而变化的写法

请教一下php变量名字随参数变化而变化的写法

WBOY
WBOYOriginal
2016-06-20 09:37:05842browse

没写过php。请教一下php变量名字随参数变化而变化的写法
  for($i=1; $i$itemId $i=$i;
}
?>

想要输出的结果是
$itemId1=1;
$itemId2=2;
$itemId3=3;

请问上面的for循环要如何填写。谢谢


回复讨论(解决方案)

for($i=1; $i<=3; $i++){  ${"itemId$i"} = $i;}echo $itemId1; //1echo $itemId2; //2echo $itemId3; //3

非常感谢。没写过php不知道规则。解决了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn