-1

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

<?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']);

?>

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

4

1 回答 1

0

我想这就是你想要做的:

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

于 2013-04-28T19:24:36.187 回答