2016-12-02 134 views
0

端添加数i有这个变量汽车在可变

$n= ""; 

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

,所以我想$号改为$数字1或$ NUMBER2所以它会得到1或2个从$ N

$live = ($number1-$r3)/60; 

,所以我已经试过这样的,但不工作

$n= "1"; 
$lv = "$number".$n;  
    $live = ($lv-$r3)/60; 

所以在这种情况下它需要是$ live =($ number1- $ r3)/ 60;

我不知道是否有办法做到这一点,如果u didnt understeand问题u能低于

+0

你所讲的'$ number'开始通过谈论'$ N'和光洁度请逻辑 – RiggsFolly

+0

in $ ni添加$ number后需要的号码 n和号码不同 – arpak

回答

0

注释一个号码添加到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 
} 
?> 

最终结果是输出这样的:

theVariableName现在是:$产品数
现在我们增加了许多。
新theVariableName现在是:$ NUMBER1

...

theVariableName现在是:$ number8
现在我们增加了许多。
新theVariableName现在是:$ number9

1
${'number' . $n} 

这将是$数字1或$ NUMBER2

+0

您自己做出了答案。你的意思是你有解决方案并发布答案? – Perumal

+0

是的,这是有效的 – arpak