Calling a function with a variable passed in the url

Okay, right now I’m storing data with php arrays and have created functions to display that data, like the following.
[php]
$myArray=array();
function myScript($myVar) {mycode;}[/php]

When I run the code as [php]<?php myScript($myArray); ?>[/php] everything works fine.

I want to open the page containing the function using a link like mypage.php?myVar=myArray but every combination I try won’t send the name of the array into the function’s variable, and the result is empty data.

Am I missing something? I feel like this is an easy fix, but it’s been stumping me all day.

You can serialize array into a string to pass it as a parameter in request string:
[php]mypage.php?myVar=<?php echo urlencode(serialize($myArray)) ?>[/php]

then in your php code - unserialize it back into array:
[php]$myArr = unserialize(urldecode($_REQUEST[“myVar”]));[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service