Im trying to pass an array as an argument in a page callback I am attempting to pass an array as a page argument in a page callback in one of my modules. The scenario is this: The user selects some photo prints and I'm trying to add all the selected photo prints to the cart. So I'm trying to pass an array through a url to use it in a function. And the photo prints can be from different photo albums. There is code to do it if all the photos are from the same album so Im currently perusing that as well. This is code I "inherited" by the way.

The URL looks like /add_selected_prints_to_cart/Array. As you can see, instead of an array of values, it's just Array. 

This is the page callback:

// Add the selected prints to the cart.
$items['add_selected_prints_to_cart/%'] = array(
  'page callback' =&gt; 'add_selected_prints_cart',
  'page arguments' =&gt; array(1),
  'access callback' =&gt; TRUE,
  'access arguments' =&gt; array('view own gallery'),
  'type' =&gt; MENU_CALLBACK
);


Like I said, I am just trying to figure out how to pass the array. Once I figure out that, the other part is easy.

Maybe there is an easier way to do this.
That happens because the code you are using is similar to the following one.

$url = url('add_selected_prints_to_cart/' . $array);


If each photo has an ID that can be used to univocally identify each photo, in the same way a node ID univocally identify a node, you could use code similar to the following to create the URL. I assume the structure of the $photos array is the following one.

array(
  'photo ID 1' =&gt; array( /* data for the photo with ID equal to 1 */),
  'photo ID 2' =&gt; array( /* data for the photo with ID equal to 2 */),
  'photo ID 3' =&gt; array( /* data for the photo with ID equal to 3 */),  
  // ...
);




$url = url('add_selected_prints_to_cart/' . implode(',', array_keys($photos)));


In this case, add_selected_prints_cart() can get the photo IDs using code similar to the following one.

function add_selected_prints_cart($photos) {
  $photo_ids = explode(',', $photos);

  // Load the photos from the database.
}


If you need to pass the array to the menu callback, I would add the array to the session variables. In this way the code would for defining the menu callback would be similar to the following one.

function mymodule_menu() {
  $items['mymodule_add_selected_prints_to_cart'] = array(
    'page callback' =&gt; 'add_selected_prints_cart',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK
  );

  return $items;
}

function mymodule_add_selected_prints_to_cart() {
  $photos = $_SESSION['mymodule_selected_photos'];
  // ...
}


(If you use 'access callback' =&gt; TRUE, the access arguments are not used.)

Otherwise, the code to convert an array to a string is similar to the following one.

$string = strtr(base64_encode(serialize($array)), array('+' =&gt; '-', '/' =&gt; '_', '=' =&gt; ''));


The code to obtain the array back from $string is the following one.

$array = unserialize(base64_decode(strtr($string, array('-' =&gt; '+', '_' =&gt; '/'))));


Bear in mind there is a limit for the URL length accepted from browsers.