[英]Form Input name with square brackets not an array in PHP
I have a form like this: 我有这样的形式:
<form action='http://zzz.com' method='post'>
<input name='fruit[1]' value='apple' />
<input name='fruit[2]' value='banana' />
</form>
on the server side this should be an array. 在服务器端,这应该是一个数组。
assert( $_POST['fruit'] === array(1=>'apple', 2=>'banana') );
In my case it is an empty string !!??!! 在我的情况下,它是一个空字符串!
assert( $_POST['fruit'] === '' );
I have no idea what the problem is - never seen this before. 我不知道问题是什么-以前从未见过。 Anyone can help plz?
有人可以帮忙吗?
PHP 5.5.12 PHP 5.5.12
use like this... 这样使用...
<form action='' method='post'>
<input name='fruit[1]' value='apple' />
<input name='fruit[2]' value='banana' />
<input type="submit" name="btn" value="OK" />
</form>
<?php
print_r($_POST['fruit']);
?>
after submitting ok button it will show you complete array 提交确定按钮后,它将显示完整的数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.