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

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

WBOY
Release: 2016-06-20 09:37:05
Original
841 people have browsed it

没写过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
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template