Php 在变量末尾自动添加数字

Php 在变量末尾自动添加数字,php,Php,我有这个变量 $n= ""; 它可以是1或2个示例:$n=“1”;或$n=“2” 所以我想把$number改成$number1或$number2,这样它从$n得到1或2 $live = ($number1-$r3) / 60; 所以我试过这样做,但不起作用 $n= "1"; $lv = "$number".$n; $live = ($lv-$r3) / 60; 所以在这种情况下,它需要是$live=($number1-$r3)/60 我不知道是否有办法做到这一点

我有这个变量

$n= "";   
它可以是1或2个示例:$n=“1”;或$n=“2”

所以我想把$number改成$number1或$number2,这样它从$n得到1或2

 $live = ($number1-$r3) / 60;
所以我试过这样做,但不起作用

  $n= "1";
 $lv = "$number".$n;    
  $live = ($lv-$r3) / 60; 
所以在这种情况下,它需要是$live=($number1-$r3)/60


我不知道是否有办法做到这一点,如果你没有理解问题,你可以在下面发表评论

要在PHP中的变量末尾添加一个数字,你可以这样做:

<?php
$theVariableName="\$number";
for ($i=0; $i < 10; $i++) { 
    echo "theVariableName is now:".$theVariableName."<br />";      //debug text
    echo "now we add a number.<br />";                            //debug text
    $theVariableName="\$number".$i;                              //actual solution
    echo "New theVariableName is now:".$theVariableName."<br />"; //debug text
    echo "<br /><br />";                                          //debug text
}
?>

最终结果将输出以下内容:

变量名称现在是:$number0
现在我们添加一个数字。
新的变量名称现在是:$number1

变量名称现在是:$number8
现在我们添加一个数字。
新的变量名称现在是:$number9


要在PHP中向变量末尾添加数字,可以执行以下操作:

<?php
$theVariableName="\$number";
for ($i=0; $i < 10; $i++) { 
    echo "theVariableName is now:".$theVariableName."<br />";      //debug text
    echo "now we add a number.<br />";                            //debug text
    $theVariableName="\$number".$i;                              //actual solution
    echo "New theVariableName is now:".$theVariableName."<br />"; //debug text
    echo "<br /><br />";                                          //debug text
}
?>

最终结果将输出以下内容:

变量名称现在是:$number0
现在我们添加一个数字。
新的变量名称现在是:$number1

变量名称现在是:$number8
现在我们添加一个数字。
新的变量名称现在是:$number9

这将是$number1或$number2


这将是$number1或$number2

您从谈论
$n
开始,然后谈论
$number
结束。请保持逻辑连接$n我添加需要在$number n后面的数字,数字不同。您从谈论
$n
开始,最后谈论
$number
请保持逻辑连接$n我添加$n后面的数字和数字是不同的,你自己回答了。你的意思是你得到了答案并发布了答案?你自己做了答案。你的意思是你得到了答案并发布了答案?