变量基于两个变量

时间:2013-04-04 19:34:38

标签: php

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'");

            }
    }
    }

}

1 个答案:

答案 0 :(得分:7)

你想要类似......

$link = ${$title."_" . $id};

或者

${"title_" . $id};

参见此参考: http://php.net/manual/en/language.variables.variable.php