php for loop奇怪問題

$a1 = 1;
$m1 = 2;
$a2 = 3;
$m2 = 4;

$ea1 = $a2 - $a1;
$ea2 = $m2 - $m1;

echo "ea1 = ($ea1) ea2 = ($ea2)";係而到佢係會出到ea1 = (2) ea2 = (2)

$abc1 = $ea1;
$abc2 = $ea2;
echo "abc1 = ($abc1) abc2 = ($abc2)<br />";但係而到就abc1 = () abc2 = ()

for ($q = 0; $q < $abc1 ; $q++) {

點解ABC就出唔到個值但EA就出到,如果我唔要ABC直接將EA係FOR LOOP到行都係出唔到
求高手指教

照你上面睇係無問題

你條 code 真係咁寫? 定你改佐啲 value 放上嚟? 如果放原 source code 睇下好啲

TOP

其實差唔多,因為我簡化到咁都行唔到,所以我諗係咪PHP有而個限制
FOR LOOP 唔比用參數
所以想問下你地

TOP

其實差唔多,因為我簡化到咁都行唔到,所以我諗係咪PHP有而個限制
FOR LOOP 唔比用參數
所以想問下你地 ...
ilovemk 發表於 2015-5-20 12:16


你覺得差唔多同實際條 code 點寫係有分別, 串錯一個字已經唔同世界

你有心問真係 copy and paste 條 code 上嚟睇啦

TOP

$a1 = 1;
$m1 = 2;
$a2 = 3;
$m2 = 6;

$ea1 = $a2 - $a1;
$ea2 = $m2 - $m1;

echo "ea1 = ($ea1) ea2 = ($ea2)<br />";

$abc1 = $ea1;
$abc2 = $ea2;
echo "abc1 = ($abc1) abc2 = ($abc2)<br />";

for ($i = 0; $i < 3; $i++){
        echo "ver1.2($i)<br />";
for ($q = 0; $q < 3; $q++){
if ($q = 1) {
                echo "q = 0 <br />";
}else if ($q < 3){
                echo "q = 1 <br />";
}else{
                echo "q = 4 <br />";
}
}
}

ea1 = (2) ea2 = (4)
abc1 = (2) abc2 = (4)
ver1.2(0)
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
q = 0
點解不停係咁LOOP唔識停??
我暫時都係咁試,我諗住成功先開始寫

TOP

由而到開始就係PHP PRINT出黎個結果
ea1 = (2) ea2 = (4)
abc1 = (2) abc2 = (4)
ver1.2(0)
q = 0
q = 0
q = 0

TOP

你個問題出喺哩行

---------> if ($q = 1) {

你哩個係 assignment, 唔係 compare

你應該用 if($q==1)

TOP

係WOO,唔該師兄

TOP

試左真係這個問題,多謝你

TOP

你個問題出喺哩行

---------> if ($q = 1) {

你哩個係 assignment, 唔係 compare

你應該用 if($q==1) ...
tunster 發表於 2015-5-20 13:13

好眼利

TOP