Php 使用数组更容易放置$\u POST

Php 使用数组更容易放置$\u POST,php,arrays,post,key-value,strip-tags,Php,Arrays,Post,Key Value,Strip Tags,我曾多次尝试让价值更容易表达。我的意思是在数组中输入值,因为我不需要输入更多的值,他可以自动输入。。例如,我写: <?php $Value1 = array ( 'Somevalue1' => 'SomeValue2', 'SomeValue1' => 'SomeValue2', 'SomeValue1' => 'SomeValue2', ); // This is

我曾多次尝试让价值更容易表达。我的意思是在数组中输入值,因为我不需要输入更多的值,他可以自动输入。。例如,我写:

<?php

$Value1 = array (
             'Somevalue1' => 'SomeValue2',
             'SomeValue1' => 'SomeValue2',
             'SomeValue1' => 'SomeValue2',
             );

// This is method what i want to put in, but i dont think that its right
$Value1[0] = strip_tags($_POST['.Value1[0].']);

// Its the meaning that he put so out:

$SomeValue1 = strip_tags($_POST['SomeValue2']);
$SomeValue1 = strip_tags($_POST['SomeValue2']);
$SomeValue1 = strip_tags($_POST['SomeValue2']);

?>


我对阵列没有太多经验,我只是在学习…

我想这就是你想要做的:

// create an array with key = field-name in form
$val = array(
    'name' => null, 
    'lastname' => null, 
    'date_of_birth' => null, 
    'favorite_color' => null);

if (isset($_POST['submit'])) { // form has been sent

    // retrieve values from $_POST and store it in $val
    foreach ($val as $key => $value)
        $val[$key] = $_POST[$key];

    // show the result
    echo "<pre>";
    var_dump($val);
    echo "</pre>";

} // if isset
//在表单中创建一个key=字段名的数组
$val=数组(
'name'=>null,
“lastname”=>null,
“出生日期”=>null,
“最喜欢的颜色”=>null);
如果(isset($_POST['submit']){//表单已发送
//从$\u POST检索值并将其存储在$val中
foreach($valas$key=>$value)
$val[$key]=$\u POST[$key];
//显示结果
回声“;
var_dump($val);
回声“;
}//如果设置为

请看现场演示:

嗨,米奇,是的,这就是我要看的。。非常感谢你的分享,但是如果你不介意的话,我只有一个问题。。如何在这种编码中添加strip_标记以保护$POST?Thanks@DavySays使用“PDO”,让它负责转义数据。搜索PDO和mysqlOk,我会搜索它。非常感谢您的帮助和代码,如果我是对的,我确实按下了绿色按钮来获得您的答案。@Davysay是的,您接受了我的答案,非常感谢!享受编码的乐趣!