Within a Drupal module callback function, there is a simple custom function that intakes an array.
The custom function executes correctly when I define the input array within the Drupal module callback function. However, when I define the input array at the root level (global), the custom function within the Drupal module callback function fails.
As a test, I made the custom function simply output the contents of the input array as a string. The first method outputs correctly while the second method does not have any output. Ideally, I'd like to define the array at the global level so that it can be used by other functions.
Thoughts?
<?php
// ** Placement of array for method 2
$mapping = array(
0 => "name",
1 => "match"
);
function mymodule_menu() {
$items = array();
$items['mymodule'] = array(
'title' => 'MyModule',
'page callback' => 'myModule_main',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function myModule_main() {
// ** Placement of array for method 1
$mapping = array(
0 => "name",
1 => "match"
);
$output = myFunction($mapping);
echo $output; // ** Returned to client side via AJAX
}