phparraysposting

Posting an array into a php document


I want to be able to post an array containing...

$food = array (
   'food_1' => 'ice cream ',
   'food_2' => 'pizza'
);

<input type="text" id="in_foods[]" value="<?=$food;?>" />

to another page but it does not seem to be working. what am I doing wrong?


Solution

  • A cleaner solution will be to:

    1- convert the array into a string using the implode function:

    $foods = implode(',',$foods);
    

    2- Place it in the input text field to be submitted:

    <input type="text" id="foods" value="<?=$food;?>" />
    

    3- On the other page convert the string back to an array:

    $foods = explode(',',$_POST['foods'])
    

    Try ;)