PHP Iterate through $_POST and use values by name
foreach($_POST as $key => $value)
{
if (strstr($key, 'item'))
{
$x = str_replace('item','',$key);
inserttag($value, $x);
}
}
You can loop through $_POST
with foreach
like this:
foreach ($_POST as $key => $value) { ... }
And within the loop you can evaluate whether each key found by the loop matches your criteria. Something like this:
foreach ($_POST as $key => $value){
if (substr($key, 0, 4) == "item") {
$identifier = substr($key, 4);
if (isset($value['tag' . $identifier])) { inserttag('tag', $identifier); }
}
}
I'm not 100% sure what is actually real and what is just a placeholder in your question though. Maybe I took something for solid fact that actually isn't. You might need to explain your wishes in more detail. ;)