foreach ($_POST as $key => $value)
之后的变量如title_1,title_2,title_3。我需要将$ title等同于$ title_ + $ id
我尝试了什么
$link = ${$title_ . $id};
$title= $title_[$id];
$title= $title_[$id];
代码
foreach ($_POST as $key => $value)
{
if (preg_match('/^id_(\d*)$/', $value, $matches))
{
$id = $matches[1];
if (isset($_POST['title_' . $id]))
{
//$link = ${$title_ . $id};
$title= $title_[$id];
//mysql_query("UPDATE table SET title='" . $title . "' where id='$id'");
}
}
}
}
答案 0 :(得分:7)
你想要类似......
$link = ${$title."_" . $id};
或者
${"title_" . $id};
参见此参考: http://php.net/manual/en/language.variables.variable.php