I have a function that populates an array that was created before the function started. To make the population work, I used the "global" in my function. Everything works fine with the situation below:
$parameter = 'something';
$listOne = array();
my_function($parameter);
function my_function($para) {
global $listeOne;
...some code
$listeOne[0] = 'john';
$listeOne[1] = 'lugano';
}
I would like to pass an array to be used in the function when calling the function. The idea would be:
$parameter = 'something';
$listOne = array();
$listTwo = array();
my_function($listOne, $parameter);
...some code
my_function($listTwo, $parameter);
function my_function($list, $para) {
...some code
$list[0] = 'john';
$list[1] = 'lugano';
}
Also, according to what I read, using the global is probably not the best ... I saw some people use and sign somewhere and say it is better. But I do not understand and do not find information about this "method" ... I hope I understand. Thank you in advance for your answers. Greetings. Mark
source
share