我想根据这种模式打印多个对象:
If there is 1 object, print 0
If there is 2 objects, print 0 1
If there is 3 objects, print 0 1 2
我尝试了以下代码:
for($i = count($nodes) ; $i >= 0 ; $i--){
print $i;
}
但结果是:
If there is 1 object, print 0 1
If there is 2 objects, print 0 1 2
if there is 3 objects, print 0 1 2 3
我不能用。我怎样才能做到这一点?
答案 0 :(得分:3)
你应该这样使用:
$n = 3; // where n is no. of object
for($i=0; $i<$n; $i++){
print $i." ";
}
//output 0 1 2