I have a little snippet of code and i can’t make it work.
$dict = array('401003' => "Test")
function getID ($tempid) {
$id = '<span title="'.$tempid.'">'.$dict[$tempid].'</span>';
return $id;
}
echo getID('401003');
echo $dict['401003'];
I expected to get the ‘Test’ twice, but only the second echo returned me the ‘Test’.
Something seems to be wrong with the $dict[$tempid] in the function
Can you guys help me please?
This is to do with the variable scope, you do not have access to the
$dictvariable inside your function. You can work around this by declaring$dictas global, or by passing it to your function, you could refactor it like this: