[nycphp-talk] url pass array as parameter
Ken Robinson
kenrbnsn at rbnsn.com
Tue Jul 1 06:24:17 EDT 2008
At 12:13 AM 7/1/2008, Anirudh Zala wrote:
>On Tuesday 01 Jul 2008 03:09:48 Tim Lieberman wrote:
> > Passing arrays in a query string is the wrong way to do it. Too many
> > things can go wrong.
>
>True. It is not proper way. But if you still want to pass such data using GET
>method then you can build Query string as shown below:
>
>$cartStr='cart[0]=val1&cart[1]=val2'; // assuming that array keys are
>numeric.
You can take advantage of the mechanism in PHP that's used to use
arrays in forms:
<?php
$cart = array('item one','item two','item three');
$urlstr = 'gallery.php?final[]=' . implode('&final[]=',$cart);
echo '<a href="' . $urlstr . '">Go</a>';
?>
Then in gallery.php
<?php
if (isset($_GET['final']))
echo implode("<br>\n",$_GET['final']);
?>
Ken
More information about the talk
mailing list