Php for loop with 2 variables?

2019-01-17 20:26发布

is it possible to do this? (here is my code)

for ($i = 0 ; $i <= 10 ; $i++){
  for ($j = 10 ; $j >= 0 ; $j--){
     echo "Var " . $i . " is " . $k . "<br>";
  }
}

I want something like this:

var 0 is 10

var 1 is 9

var 2 is 8 ...

But my code is wrong, it gives a huge list. Php guru, help me !!

7条回答
我想做一个坏孩纸
2楼-- · 2019-01-17 20:54

You could also add a condition for the second variable

for ($i=0, $k=10; $i<=10, $k>=0 ; $i++, $k--) {
    echo "Var " . $i . " is " . $k . "<br>";
}
查看更多
登录 后发表回答