-3

I want to print the value of form fields using an array. I have two fields in file1.php, name and email, which I am passing to file2.php using post and storing it in an array.

<?php 
    $name = $_post['name']
    $email = $_post['email];
    function personal($name, $email) {
        $return = array($name, $email);
        print_r($return); //Output(Array ( [0] => alisha [1] => alisha@gmail.com )
        echo implode('<br>', $return);  //Output alisha      alisha@gmail.com

?>

How do I print these values, alisha and alisha@gmail.com, in the file1.php when the user go to the previous page using the submit button without using a session and a cookie?

<input type=text name=name value="**print alisha here array[0]**">
<input type=text name=email value="**print alisha@gmail.com here array[1]**">
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
  • 2
    value="", but i don't understand why you should use array when you have the variables allready ($name, $email))? – bksi Oct 28 '14 at 23:18
  • @bksi - also has them as $_POST['email'] & $_POST['name']. Any reason why they have gone through 2 variable changes for the same values? – ggdx Oct 28 '14 at 23:25
  • @bksi -its because i am passing this variable to many pages using hidden variable & function and at last store all the values in array. Without array i am able to solve this. – user3385022 Oct 28 '14 at 23:40

1 Answers1

0
<input type="text" name="name" value="<?= $return[0]; ?>" />

<input type="text" name="email" value="<?= $return[1]; ?>" />

You just need to echo the array key (0 for name, 1 for email).

ggdx
  • 2,672
  • 4
  • 28
  • 45