嘿所有我只是想确保我正确地将值添加到我的数组varable:
$post_values = array(
"x_first_name" => $_POST['first_name'],
"x_last_name" => $_POST['last_name']
);
如果有人可以确认它的方式,请执行:o)
大卫
答案 0 :(得分:2)
这有效,但这些也有效:
$post_values = array();
$post_values['x_first_name'] = $_POST['first_name'];
$post_values = array();
array_push($post_values, $_POST['first_name'];
// but now you don't have the desired index, just numeric indexes
您可能还想首先检查帖子值是否存在:
if (isset($_POST['first_name']) {
$post_values['x_first_name'] = $_POST['first_name'];
}
答案 1 :(得分:-1)
你也可以
$post_values = array();
foreach ($_POST as $k => $v) {
$post_values['x_' . $k] = $v;
}
请确认POST输入!
$post_values['x_' . htmlentities($k, ENT_QUOTES)] = htmlentities($v, ENT_QUOTES);