Pergunta

I did try many times to make values easier to put. It's my meaning to put values with array, because I don't need to type more values then, he can put it automatically.. For example, I write:

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

?>

I don't have to much experience with array, I am just learning...

Foi útil?

Solução

I guess it is this what you want to do:

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

see live demo: http://codepad.viper-7.com/j03DtO

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top