更容易把$_POST与数组


Easier to put $_POST With Array

我确实多次尝试使值更容易放置。我的意思是用数组放值,因为我不需要输入更多的值,他可以自动放。例如,我写:

<?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

查看实时演示:http://codepad.viper-7.com/j03DtO