I have a class in php. Inside class I have a function called setContent(). Inside that I have multiple variable with values. I have taken those variable values and stored them in an array.In another function I wanted to get all the variables stored in an array. So my code is like this
class foo{
public function setContent() {
global $my_array;
$var1 = 'variable 1';
$var2 = 'variable 2';
$var3 = 'variable 3';
$var4 = 'variable 4';
$var5 = 'variable 5';
new_array = array();
$my_array = array_push($new_array, $var1, $var2, $var3, $var4, $var5);
}
public function getContent() {
global $my_array;
var_dump($my_array);
}
}
But when I am doing var_dump($my_array). Its showing NULL. So can someone tell me how to get those variables inside other function in an array. Any help and suggestions will be really appreciable.
global $my_array = array();