Changing variable name (numbering) or adding numbers to a variable in asc order to assign values

别等时光非礼了梦想. 提交于 2019-12-25 07:33:04

问题


How to change the variable name numbering in ascending order to assign values to them. eg: car_1, car_2, car_3, car_4........ so on.. my coding is something like;

for (i=1; i<20;i++){
$var[i] = $_POST["car_"i];
}

foreach ......so on........

echo $var[12]."<br/>";

I need a way to increase the number of 'car_' to assign each car value to the '$var' array. I have tried to add it like this:

$var[i] = $_POST["car_"&i];

AND

$var[i] = $_POST["car_"i""];

and none of these work. I would very much appreciate your help to solve this.


回答1:


If you mean to append strings then do this:

for ($i=1; $i<20;$i++) {
   $var[$i] = $_POST["car_".$i];
}


来源:https://stackoverflow.com/questions/36597999/changing-variable-name-numbering-or-adding-numbers-to-a-variable-in-asc-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!