Using array keys to call from multidimensional $_POST 'ed arrays?
Thank you for looking at and taking time to answer my question!
I would like to use a multi-dimensional array in a form on my site and then access it using the keys; Like so.
<form method="post" action="somescript.php">
<input type="text" name="name[1][title]">
<input type="text" name="name[1][descritpion]">
</form>
I would then like to access both the index, since that is the ID, and the value of the given _post'ed element. Something like
$keys = array_keys($_POST['name']);
foreach($keys as $id)
{
echo "title: " . $_POST['name']['开发者_运维技巧title'][$id];
echo "description: " . $_POST['name']['description'][$id];
echo "id: " . $id;
}
Now, the above looks nice and it prints out the correct $id but thats about it. I assume I am putting the "title" or "description" array calls in the wrong place but cannot figure it out. Could someone kindly point me in the right direction?
In your PHP, you are looking for $_POST['name']['title'][$id]
, but in your HTML you have name[1][title]
.
These are not the same array. You either need to change the HTML to name[title][1]
, or the PHP to $_POST['name'][$id]['title']
.
It doesn't matter which you use, just be consistent, though I suggest using name[title][1]
as that may be easier to work with.
精彩评论