I write this in a page :
require_once("pdf/tab_activite.php");
...
foreach ($tab["activite"] as $key => $value)
{
...
}
Inside the tab_activite.php there is this :
...
$list = new activite($this->db);
$list->lireParNiveau($critere);
$tab["activite"] = $list->tableau ;
...
Then in the log there is :
[10-Oct-2012 10:30:48] PHP Notice: Undefined index: activite in C:\wamp\www\mp\models\objet.class.php on line 543
[10-Oct-2012 10:30:48] PHP Warning: Invalid argument supplied for foreach() in C:\wamp\www\mp\models\objet.class.php on line 543
So how to manipulate correctly the $tab[“activite”] variable ?
Since the
require_once()is called inside a function,$tab["activite"]exists only in that function’s scope. Add the statementglobal $tab;to the filetab_activite.phpbefore using the$tabvariable to extend it’s scope so that the main program can see it as well.EDIT: Another problem could occur if you call the function multiple times, as the file is included only once when using
require_once(). If this is the case, replacerequire_once()withrequire()and see if that helps.