Pass array in php from one php page to other

Here is a simple way to pass your array in post method.

In first page we are creating a form.In that form creating hidden 
controls with arrray value as shown below.

In second part (display.php) we can extract values from request 
variable. 
Here is the code 
 
///////////////////////////////////////////////////

echo '<form name="form" method="post" action="display.php">';


$i=0;

foreach($arr as $key => $value)
{
$i++;
echo '<input type="hidden" name="val['.$i.']" value="'.$value.'"/>';
}

echo '</form>';







////////////////Copde in display.php page ////////////////



foreach($_REQUEST['val'] as $key => $value)
{


echo $value;
}

//////////////////////////////////////

If you found some good method to pass array Share with us as comments 
with regards SREEHARI

1 comments:

Hari said...

In another way we can also pass get variables