尽管花费了数小时的谷歌搜索和阅读各种书籍,但我似乎无法在我正在尝试创建的 PHP 程序中输出我的目标(我是新手!)。基本上,一开始我只是想创建一个简单的数组并尝试输出我最喜欢的足球队以及他们的位置或关于他们的事实,然后再进入任何太复杂的事情(不幸的是,即使这也有点困难!)。这是我到目前为止所得到的:
<?php
<html>
<head>
<title>Football teams</title>
</head>
<body>
<?php
$numbers = array("one", "two", "three", "four");
$counter = 0;
do {
if($counter > 0) {
$verse = true;
}
echo "$numbers[$counter] " ;
if ($verse) {
echo "Team " ;
}
else {
echo "Teams" ;
}
print "are the best teams in the world <br/>" ;
$counter++;
} while($counter < 4);
$football = $counter;
while($football) {
echo "$numbers[$football] men, " ;
if ($verse) {
echo "n<br/>" ;
}
echo "and rarely lose any games\n\n<br/><br/>" ;
$football--;
}
?>
</body>
</html>
现在它可以正常工作,但没有任何错误,但它到处都是,而且顺序不正确,所以我很感激任何帮助。当没有错误时,我自己看不出有什么问题,所以我怀疑其中一个循环有问题。
谢谢你。
我希望得到:
one team are the best team in the world
and rarely lose any games
two teams are the best team in the world
two teams
and rarely lose any games
three teams are the best team in the world
three teams
and rarely lose any games
four teams are the best team in the world
four teams
and rarely lose any games
等等
但我得到的是:
one team are the best team in the world
two teams are the best team in the world
three teams are the best team in the world
four teams are the best team in the world
更新:
$counter = 0;
do {
if($counter > 0) {
$verse = true;
}
echo "$numbers[$counter] " ;
if ($verse) {`
echo "team " ;
}
else {
echo "teams " ;
}
print "are the best teams in the world<br/>" ;
$football = $counter;
while($football) {
echo "$numbers[$football] teams, " ;
if ($verse) {
echo "<br/>" ;
}
echo "and rarely lose any games\n\n<br/><br/>" ;
$mower--;
}
$counter++;
} while($counter < 10);
?></body>
</html>
使用这段代码我几乎完成了我的目标,这是我得到的输出:
one team are the best team in the world,
two teams are the best team in the world,
two teams,
and rarely lose any games
three teams are the best team in the world,
three teams,
and rarely lose any games
two teams,
and they rarely lose any games,
four teams are the best team in the world,
four teams,
and they rarely lose any games,
但是,我想要的是:
one team are the best team in the world,
and they rarely lose any games,
two teams are the best team in the world,
two teams,
and they rarely lose any games,
three teams are the best team in the world,
three teams, two teams,
and they rarely lose any games,
four teams are the best team in the world,
four teams, three teams, two teams,
and they rarely lose any game,
谢谢如果有人可以帮助!