how to get var name and value from function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,
this one I can't figure out:

I have to assign value of an array to variable named after key of the
array several times in my project to , e.g. after I submit a form with
personal info I have
$_POST['name'] = 'john doe';
$_POST['address'] = '123 main st.';
$_POST['city'] = 'urbandale';
$_POST['zip'] = '12345';
$_POST['phone'] = '123-456-7980';
etc.

Then I assign value to the var name:
foreach ($_POST as $key => $value)
{
    ${$key} = $value;
}
and then validate submitted.

Though, to avoid writing all over again the same lines (even it's only 3
lines) I was thinking to create a function something like:

function value2var($array, $print=0)
{
    foreach ($_POST as $key => $value)
    {
        ${$key} = $value;
        echo ($print ==1) ? $key.': '.$value.'<br>';     // to test
results and seeing array variables and values
    }
}

value2var($_POST, 1);

but, I don't know how to get info from function back to script?!?!?
:-(

any help appreciated.

-afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux