I have code in html:
<input type="text" name="product[0][name]" value="name of product 1"/>
<input type="text" name="product[1][name]" value="name of product 2"/>
<input type="text" name="product[2][name]" value="name of product 3"/>
<input type="text" name="product[3][name]" value="name of product 4"/>
I try to send this via $_POST.
When im using
print_r($_POST['product']);
I got list of my products for ex:
Array
(
[product] => Array
(
['201'] => Array
(
['name'] => J5313 BEŻOWE
['price'] => 14.99
['quantity'] => 1
['size'] => 36
['product_subtotal'] => 14.99
)
['200'] => Array
(
['name'] => J5313 SZARE
['price'] => 14.99
['quantity'] => 1
['size'] => 37
['product_subtotal'] => 14.99
)
)
)
Everything is ok, but if i want to echo my array variables i have empty vars!
Its my code:
foreach($_POST['product'] as $key => $value){
echo "product key: $key, product name: ".$value['name']."";
}
What php write in document:
product key: 0, product name:
product key: 1, product name:
product key: 2, product name:
product key: 3, product name:
$key variable is not empty but $value is empty!
I try to change name of $value var but its not solve my problem.
Any one knows what i must to to?
Since it’s unclear, based on your code, why you’re experiencing this problem there are a few debugging steps you could take:
Show all warnings
Add those two lines to your script and run it; if there are any obvious issues like missing indices it will echo warnings in your page.
Add more debugging
Since your loop can find the keys, you should
var_dump($value);inside the loop to figure out if perhaps you made a typo (although that would have shown up by showing all warnings.