simple external variables to hooks Using drupal 7, Views 3, I have a function (present on Leaflet Module) which takes only 2 parameters. I use this hook function to print resulting points from view in different colors
//Allow modules to alter the points data while rendering a leaflet views row.
MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) 
{
  if (isset($result-&gt;number)) 
 {
  // Add number value to every points data entry, if present.
    array_walk($points, function(&amp;$point, $key, $number) {
     $point['number'] = $number;
   }, $result-&gt;number);
 }
}

I am trying to use this hook to take variables from outside the function.
For example:
$data='heeeello';

MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) 
 {
  echo $data;
 }

Just returns NULL. Tried setting it up as Global (which should already be, but just in case), also variable_set($data,'hello')... no success.
Executing the function passing the params works neither:
MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points,$param)
{
  echo $param;
}

thanks in advance
EDIT
I want to populate an external array based on the data processed by my hook (see below MY_MODULE_leaflet_views_alter_points_data_alter)
This final array has to contain unique values. On standard PHP I would access the external array and populate recursively it but I have problems accessing this array via my hook.
Using global doesn't work, but it works using variable_set and variable_get, but it means that each time the hook access the variable (variable_get(param)), the array starts empty again.
$array = array();

variable_set('my_array', $array);

//testing global, doesnt work
$test=array();

MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) {

    global $test;
    var_dump($test); //NULL
    
    $my_array= variable_get('my_array');
    //I will get allways an empty array... even if its later correctly populated

    //fetching results from the hook
    $name=$result-&gt;name;

    if (!in_array($name,$my_array))
      {
        array_push($my_array,$name);
      }

    //plots just a value (array is not recursively populated, as allways start empty inside the hook)  
    var_dump($my_array);
 }
This is a php issue.

$data = 'heeeello';

MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) {
  echo $data; // $data is NULL, will also throw a notice
}

MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) {
  global $data;
  echo $data; // $data is 'heeeello'
}


regarding your variable_set, the params are different:

$data = 'heeeello';
variable_set('hello', $data);
MY_MODULE_leaflet_views_alter_points_data_alter ($result, &amp;$points) {
  $data = variable_get('hello');
  echo $data; // $data is 'heeeello'
}


RE edit: this goes towards your extension:
variable_set() is not designed to do sets on every request, variables should be quiet consistent, every variable_set will clear your cache (to some extend), abusing this will lead to a lot of performance problems.

If you need a cache use cache_set and cache_get, for singletons/ static stuff use drupal_static. The global variable $test you are using right now in your question, should not return NULL but array(), everything else looks like a different problem.

If you want to build up a storage backend create proper tables using hook_schema or (advanced) build your own entities.

edit: almost forgot, your code from above, is not working because you are not saving that variable again, so even for the second run it will always be empty.