Reputation: 591
DEMO.PHP
<form action = "test.php" method="post">
<input type="checkbox" name="vehicle[]" value="'Peter'=>'35'">I have a bike<br>
<input type="checkbox" name="vehicle[]" value="'Ben'=>'37'">I have a car <br>
<input type="submit" value="Submit">
</form>
test.php
<?php
if(isset ($_POST["vehicle"]))
{
$v = $_POST["vehicle"];
foreach($v as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
}
?>
My $x didnt get Peter or Ben?
How can I get the key and value separately?
Upvotes: 0
Views: 2152
Reputation: 943510
If you name your fields ending in []
, then PHP will construct a regular array from them.
Using =>
in the value will have no special meaning.
If you want to specify the key names that PHP will parse the form data into, then you do so in the name:
name="vehicle[Peter]" value="35"
Upvotes: 3