将数组转换回PHP变量

将数组转换回PHP变量,php,arrays,escaping,Php,Arrays,Escaping,我将17个变量放入一个数组中,然后对它们运行mysqli\u real\u escape\u string,因为这比对每个变量单独执行要容易得多 $rescape = array($username, $fname, $lname, $nationality, $landline, $mobile, $email, $nationalid, $passport, $dob, $street, $towncity, $postcode, $country, $country, $favourite

我将17个变量放入一个数组中,然后对它们运行
mysqli\u real\u escape\u string
,因为这比对每个变量单独执行要容易得多

$rescape = array($username, $fname, $lname, $nationality, $landline, $mobile, $email, $nationalid, $passport, $dob, $street, $towncity, $postcode, $country, $country, $favourite, $rentpw);
$rescape = array_map('mysqli_real_escape_string', $rescape);
如果我理解正确,现在转义字符串都存储在
$rescape
中的数组中


将它们返回到单个变量中的“最短”方法是什么?

您可以使用
列表执行此操作:

list($username, $fname, $lname, $nationality, $landline, $mobile, $email, $nationalid, $passport, $dob, $street, $towncity, $postcode, $country, $country, $favourite, $rentpw) = $rescape;
如果将
$rescape
存储为键/值对,甚至可以使用


请注意,
mysqli\u real\u escape\u string
需要连接的链接作为第一个参数。大概是这样的:

$rescape = array_map(function($e) use ($connection) {
    return mysqli_real_escape_string($connection, $e);
}, $rescape);
或者,如果您以面向对象的方式使用mysqli,只需

$rescape = array_map(array($mysqli, 'real_escape_string'), $rescape);

应该可以做到这一点。

$rescape=array\u map($connection,'mysqli\u real\u escape\u string',$rescape)
像这样吗?我在回答中添加了一个示例,为什么我不需要在示例2中的
real\u escape\u字符串上包含
mysqli\u
?在第一个示例中,您有
mysqli\u real\u escape\u字符串($mysqli,$e)
。在我的例子中,连接(
$connection
)是否仅在第一个参数中?e、 g:
mysqli\u real\u escape\u string($connection,$e)
(我很困惑,因为函数也使用了
$mysqli
)是的-我重命名它只是为了避免混淆