作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<!DOCTYPE html>
<html>
<head>
<title>My Form</title>
<meta charset="UTF-8" />
</head>
<body>
<form method="get">
<div>Name
<input name="name" size="15" type="text" />
</div>
<select multiple="yes" name="colors[]">
<option> 1 </option>
<option> 2 </option>
<option> 3 </option>
<option> 4 </option>
<option> 5 </option>
</select>
</form>
<?php
$number=10;
echo "hello";
if (isset($_GET["name"])){
echo " ".$_GET["name"];
echo "<br />";
}
echo count($_GET["colors"]), " ", $_GET["colors"], "<br />";
echo $_GET[$colors[0]]," is your first color.";
if(isset($_GET["$colors"])){
echo "You must like ";
for($colornum=0;$colornum<count($_GET["$colors"]);$colornum++){
echo $_GET[$colors[$colornum]]," ";
}
}
?>
</body>
</html>
为什么这行不通? select multiple 不在数组中正确输出,或者可能有很多调试内容对我的理解没有多大帮助。我收到 undefined index 和变量错误。这是我选择选项 1-3 后的输出:
Name
hello jimbo1qaz
3 Array
Notice: Undefined variable: colors in E:\xampp\htdocs\myform.php on line 28
Notice: Undefined index: in E:\xampp\htdocs\myform.php on line 28 is your first color.
Notice: Undefined variable: colors in E:\xampp\htdocs\myform.php on line 29
最佳答案
//this should be $_GET['colors'][0]
echo $_GET[$colors[0]]," is your first color.";
//the , is wrong, you need to use . (point)
echo $_GET[$colors[0]]," is your first color.";
//Delete the $
if(isset($_GET["$colors"])){
//it's $_GET['colors']
for($colornum=0; $colornum<count($_GET["$colors"]); $colornum++){
//Here you need to use $_GET['colors'][$colornum]
echo $_GET[$colors[$colornum]]," ";
}
要输出数组,请使用 print_r() 而不是 echo:
print_r($_GET["colors"]);
关于php - 多选到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11426339/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!