$genreList; function directorGen($array) { foreach($array as $value) { $genreList[] = $value; } } //later.. directorGen($title->genres());
This code results in a NULL array. If I replace $genreList[] = $value with echo $value everything prints out like expected. Any ideas?
If
$genreListis a global variable, there’s your problem: it’s a scope issue. It can easily be fixed with:Note: while not strictly necessary I also initialized it, which I think is good practice.
If
directorGen()is a member function and$genreListis a data member then change to: