Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending arrays through URL

Status
Not open for further replies.

teriyaki

Technical User
Dec 9, 2002
1
PH
Hi, I'm trying to pass variables from one php script to another through the URL (e.g. default.php3?myvar=4).<br><br>Can I pass arrays?&nbsp;&nbsp;If so, how?&nbsp;&nbsp;I can't write something like this in my php script:<br><br>print &quot;$default.php3?myarray=$myarray&quot;;
 
Well, you have two options.&nbsp;&nbsp;You can use the implode() function to convert the array to a string (for instance, to make a comma delimited string of an array, you can do implode(',',$array);).&nbsp;&nbsp;Then explode() the string once you've got it in your new page.<br><br>If the array is multidimensional, however, I would recommend using the serialize() function.&nbsp;&nbsp;serialize() creates a string representation of a PHP value, whether it be an integer, an array or an object.&nbsp;&nbsp;If the variable $data is your array, or whathaveyou, you can use:<br>$newpage = &quot;default.php?mydata=&quot; . urlencode(serialize($data));<br>And when you import it in default.php, you can just do:<br>$anArray = unserialize($mydata);<br><br>Good luck,<br>sophie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top