PDA

View Full Version : More than one variable


mr_ego
10-03-2002, 02:28 PM
This is my query string:

?action=delete&id=1&id=3

i would like to read the data in "id" data into an array.
Something like:


$_GET['id'][0] Returns 1
$_GET['id'][1] Returns 3.


how do you do this?

firepages
10-03-2002, 05:16 PM
you cant,
you can use POST to send arrays or you could serialize() (or implode()) an array and then send that via the query string

example (POST would still be better :))


<?
if(!$_REQUEST['delete'])
{
$var[0]='hello'; $var[1]='sweet';$var[2]='world';
$yaks=base64_encode(serialize($var));
}
?>

<a href="<?=$_SERVER['PHP_SELF'];?>?delete=1&var=<?=$yaks;?>">whoosh</a>

<?
if($_REQUEST['delete'])
{
$var=unserialize(base64_decode($_REQUEST['var']));
echo implode(' ',$var);
}
?>

mordred
10-03-2002, 05:29 PM
Well, it could get it to work simply by using GET. Call your file like this:


http://yourdomain.com/test.php?id[]=2&id[]=3


and then have in test.php


var_dump($_GET['id']);


and that gave me


array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "3"
}


so it all boils down to adding some brackets in the query string, to denote that you want these variables to be stuck together into an array by php.

firepages
10-03-2002, 07:49 PM
well best ignore me then cos I did not realise you could do that ! - still living and learning :)