Reputation: 51
How to read array posted from form repeater
the best is the array got from a form post..
Array (
[products] => Array (
[0] => Array (
[pid] => 1
[qty] => 2
)
[1] => Array (
[pid] => 1
[qty] => 2
)
[2] => Array (
[pid] => 1
[qty] => 2
)
)
)
my question is how to read value like this:
$pid[1]= 1
$qty[1] = 1
Upvotes: 0
Views: 239
Reputation: 588
You can access the array values like this.
<?php
$array = array("products"=> [["pid" => 1 , "qty" => 2 ],
["pid" => 2 , "qty" => 3 ],
["pid" => 3 , "qty" => 4 ]]);
echo "PId: " . $array["products"][0]["pid"] . "<br>";
echo "qty: " . $array["products"][0]["qty"] . "<br><br>";
print_r($array);
?>
see the PHP fiddle for the working version
Upvotes: 2