Not being able to access global array from in php

i am having the following situation in a wordpress theme which I want to modify in a file called navigation.php

$array_test = array (1,2,3,4);

function func1()
{
  global $array_test;

  echo "test"; // to ensure that the function has been called
  echo $array_test[2]; // this writes nothing, though the function is being called
}

in the file called header.php the function func1 is being called, still the value of $array_test[2] cannot be accessed,

Read More

Do you have any ideas?

EDIT:
i suspect it is an issue with wordpress or the theme, but i am not sure
the theme is the free health_care_wp_theme

Related posts

Leave a Reply

1 comment

  1. In navigation.php, (in case if there’s no class in that file,define one)

    class Nav
    { 
         public $array_test = array(1,2,3,4);
    
         public function func1()
         {  
           echo "test"; // to ensure that the function has been called
           return $this->array_test[2]; 
         }
    
         public function access_within_class()
         {   
           print_r($this->array_test); 
         }     
    }
    

    In header.php

    include 'path/to/navigation.php';
    
    $nav = new Nav();
    $the_array = $nav->func1(); 
    echo $the_array;