How to add the output of a php-function to a list
所以我正在尝试编写代码来做以下非常基本的事情:
*从 html 输入表单中取一个数字
*取一个计数器,从0循环到输入数字
*在 php 输出中将数字作为列表项获取,除非它可以被 3 或 5 整除,它们分别获取 ping 和 pong 作为输出值。
目前,可悲的是,这不起作用,我得到的只是tite
第一个问题:- form 方法是
第二个是:-
<MMKG1>
"+ $outputMessage +"
<MMKGX1>
";
<MMKG1>
".$outputMessage."
<MMKGX1>
";
第三个是:-
所以您的第二页代码必须如下所示:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | <?php $inputNumber = $_POST["inputNumber"]; function colorFate($inputNumber) { $new_array = array(); $outputMessage =""; if ($inputNumber < 100){ for ( $counter = 1; $counter <= $inputNumber; $counter++) { if ($counter % 5 === 0 && $counter % 3 === 0){ $new_array['Ping-Pong'][$counter] = $counter; }else if ($counter % 3 === 0){ $new_array['Ping'][$counter] = $counter; }else if ($counter % 5 === 0){ $new_array['Pong'][$counter] = $counter; }else if ($counter % 5 != 0){ $new_array['nothing'][$counter] = $counter; } } return $new_array; } else{ alert("Please follow the guidelines on what to enter!"); } } ?> <!DOCTYPE html> <html> <head> PHPingPong </head> <body> Read and Weep! <?php $result = colorFate($inputNumber);?> <?php foreach($result as $key=>$value){ echo" <ul> <span>$key numbers are:-".implode(',',$value)." </ul> "; }?> </body> </html> |