NYCPHP Meetup

NYPHP.org

[nycphp-talk] url pass array as parameter

Anirudh Zala arzala at gmail.com
Tue Jul 1 23:37:09 EDT 2008


On Tuesday 01 Jul 2008 19:48:27 Kristina Anderson wrote:
> url would have to be 'galleryform.php?cart[0]=val1&cart[1]=val2'
> (i'm not sure if you can use brackets [] in a URL either)
>
> or something of that nature.  remember, a querystring has to consist
> of key=value pairs (or it can be just one value if a single
> parameter)...and it will automatically BE an array after it is passed
> to the receiving page -- $_SERVER['QUERY_STRING'];

With the context of PHP, above mentioned array format is also supported for 
both GET and POST method. Remember HTTP just passes whatever Query_String you 
have passed to it. It is PHP's feature that it converts both single and 
double dimensional arrays in equivalent super globals array like $_GET, 
$_POST etc.

>
> -- Kristina
>
> > Thanks for everyone answer my question!
> >
> > One further question:
> > if
> > url=galleryform.php?$cartStr='cart[0]=val1&cart[1]=val2';
> >
> > then
> > On gallery.php page:
> > <?php$totalcart=new array()
> > $totalcart=$_GET['cartStr']
> > for($x=0;$x<$totalcart[].length;$x++)
> > {echo   $totalcart[$x];
> > }  ?>
> >
> > Is gallery.php coding is correct?I want to output array.
> >
> > Thanks again!
> >
> > > Date: Tue, 1 Jul 2008 06:24:17 -0400> To: talk at lists.nyphp.org>
>
> From: kenrbnsn at rbnsn.com> Subject: Re: [nycphp-talk] url pass array as
> parameter> > 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> > > > >
> _______________________________________________> New York PHP Community
> Talk Mailing List> http://lists.nyphp.org/mailman/listinfo/talk> >
> NYPHPCon 2006 Presentations Online> http://www.nyphpcon.com> > Show
> Your Participation in New York PHP>
> http://www.nyphp.org/show_participation.php
>
> > _________________________________________________________________
> > It’s a talkathon – but it’s not just talk.
> > http://www.imtalkathon.com/?source=EML_WLH_Talkathon_JustTalk
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php





More information about the talk mailing list