PHP echo不会显示在网页中

PHP echo不会显示在网页中,php,html,Php,Html,因此,我在编码HTML CSS和PHP方面相当新,现在我专注于PHP。 我们的教授让我们在我们的网站中加入PHP代码,没有数据库,我正试图使用for循环和echo打印一个数组 问题是回音没有显示在网页上,我现在迷路了 以下是我的密码: <html> <head> <title>PHP Loops and Sorts</title> <body> <h1>PHP Loops and Sorts</h1> <

因此,我在编码HTML CSS和PHP方面相当新,现在我专注于PHP。 我们的教授让我们在我们的网站中加入PHP代码,没有数据库,我正试图使用for循环和echo打印一个数组

问题是回音没有显示在网页上,我现在迷路了

以下是我的密码:

<html>
<head>
<title>PHP Loops and Sorts</title>
<body>
<h1>PHP Loops and Sorts</h1>

<div class="container">
<?php
$dogs=Array("Labrador Retriever","German Shepherd","Bulldog","Golden Retriever","Poodle","Beagle","Rottweiler","Yorkshire Terrier","Siberian Husky","Dachshund","Chihuahua","Pug","Great Dane","Dobermann","Shih Tzu");
$cats=Array("Persian","Siamese","Maine Coon","Ragdoll","Sphynx","British Shorthair","Abyssinian","Bengal","Scottish Fold","Himalayan","Russian Blue","Siberian","Munchkin");
$birds=Array("Canaries","Budgies","Finches","Cockatiels","Quaker Parakeets","Pionus Parrots","Poicephalus Parrots","Amazon Parrots","Pyrrhura Conures","Peach-Faced Lovebirds");
$fishes=Array("Koi","Fantail","Oranda","Comet","Black Telescope","Butterfly Tail","Ryukin","Goldfish","Lionhead","Mirror Carp");

function countsize($array,$size){
    $size = count($array);
    return $size;
}

if(isset($_POST['btnShow']) )
    {
        $arraypick=$_POST['formAnimal'];
        $arrsize = countsize($arraypick,$size);
        for(&x = 0,$x<$arrsize,$x++){
            echo $arraypick[$x] . "<br>";
        }
    }
?>
Breeds of different kinds of animals. Select what animal's breed to be shown:<br>
    <select name="formAnimal">
  <option value="">Choose animal</option>
  <option value="dogs">Dog</option>
  <option value="cats">Cat</option>
  <option value="birds">Bird</option>
  <option value="fishes">Fish</option>
</select><br><br>
<div style="margin:auto,text-align:center;text-align:center">
<INPUT TYPE = "Submit" Name = "btnShow" VALUE = "Show List">&emsp;
<INPUT TYPE = "Submit" Name = "btnAsc" VALUE = "Show Ascending">&emsp;
<INPUT TYPE = "Submit" Name = "btnDes" VALUE = "Show Descending">
</div>


<?php

echo $size

?>

</div>
</body>
</html>

for循环的语法不正确。查看


此外,$size变量从未在您使用的范围内声明。

for循环的语法不正确。查看


另外,$size变量从未在您使用它的作用域中声明。

没有了解如何使用$arrsize,但在初始化循环时使用了&x而不是$x

for($x = 0,$x<$arrsize,$x++){
  echo $arraypick[$x] . "<br>";
}

没有了解如何使用$arrsize,但在初始化循环时使用了&x而不是$x

for($x = 0,$x<$arrsize,$x++){
  echo $arraypick[$x] . "<br>";
}

更改以下代码行:

$dogs=Array("Labrador Retriever","German Shepherd","Bulldog","Golden Retriever","Poodle","Beagle","Rottweiler","Yorkshire Terrier","Siberian Husky","Dachshund","Chihuahua","Pug","Great Dane","Dobermann","Shih Tzu");
$cats=Array("Persian","Siamese","Maine Coon","Ragdoll","Sphynx","British Shorthair","Abyssinian","Bengal","Scottish Fold","Himalayan","Russian Blue","Siberian","Munchkin");
$birds=Array("Canaries","Budgies","Finches","Cockatiels","Quaker Parakeets","Pionus Parrots","Poicephalus Parrots","Amazon Parrots","Pyrrhura Conures","Peach-Faced Lovebirds");
$fishes=Array("Koi","Fantail","Oranda","Comet","Black Telescope","Butterfly Tail","Ryukin","Goldfish","Lionhead","Mirror Carp");

function countsize($array,$size){
$size = count($array);
return $size;
}

致:


更改以下代码行:

$dogs=Array("Labrador Retriever","German Shepherd","Bulldog","Golden Retriever","Poodle","Beagle","Rottweiler","Yorkshire Terrier","Siberian Husky","Dachshund","Chihuahua","Pug","Great Dane","Dobermann","Shih Tzu");
$cats=Array("Persian","Siamese","Maine Coon","Ragdoll","Sphynx","British Shorthair","Abyssinian","Bengal","Scottish Fold","Himalayan","Russian Blue","Siberian","Munchkin");
$birds=Array("Canaries","Budgies","Finches","Cockatiels","Quaker Parakeets","Pionus Parrots","Poicephalus Parrots","Amazon Parrots","Pyrrhura Conures","Peach-Faced Lovebirds");
$fishes=Array("Koi","Fantail","Oranda","Comet","Black Telescope","Butterfly Tail","Ryukin","Goldfish","Lionhead","Mirror Carp");

function countsize($array,$size){
$size = count($array);
return $size;
}

致:

ifisset$\u POST['btnShow']是否确定已设置

根据我们在您的代码中的内容,您甚至无法发布,您丢失了表单标记

尝试用以下内容包装您的输入:

<form method="POST">
    <!--inputs-->
</form>
ifisset$\u POST['btnShow']是否确定已设置

根据我们在您的代码中的内容,您甚至无法发布,您丢失了表单标记

尝试用以下内容包装您的输入:

<form method="POST">
    <!--inputs-->
</form>

您需要先关闭头部标签,然后再关闭身体标签

您也不需要将大小传递给方法计数大小

function countsize (&array) {
    return count(&array);
}

您需要先关闭头部标签,然后再关闭身体标签

您也不需要将大小传递给方法计数大小

function countsize (&array) {
    return count(&array);
}

for循环的语法不正确。请将for循环更新为$x=0$XYFOR循环的语法不正确。请将for循环更新为$x=0$席先生,你的目标是在顶部显示每个变量上列出的动物。所以我会再编辑一次我想你的目标是在顶部显示每个变量上列出的动物。所以我会再编辑一次,非常感谢。最终,这是我没有的一段代码,这就是它无法运行的原因。太棒了!很高兴我能帮上忙:谢谢。最终,这是我没有的一段代码,这就是它无法运行的原因。太棒了!很高兴我能帮忙:D