Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Passing an array to the URL

    • 0
    • 1
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 195
    Comment on it

    Sometime you may need to pass the array in the url. You can do this as following:

    $array["a"] = "A";
    $array["b"] = "B";
    $array["c"] = "C";
    $array["d"] = "D";
    $str = serialize($array);
    $strenc = urlencode($str); 
    print $str . "\n";
    print $strenc . "\n"; ?> 

    This ll give you :




    Serialize will give you the storable representation of the array:

    This is useful for storing or passing PHP values around without losing their type and structure.

    $url ='http://page&#95;no&#95;2.php?data=".$strenc."';

    If you want to pass this array to some other page in url you need to unserialize the data from url

        $strenc2= $&#95;GET['data'];
        $arr = unserialize(urldecode($strenc2));


     array(4) {
      string(8) "A"
      string(10) "B"
      string(6) "C"
      string(11) "D"

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: