Return an array value from included file in a function-Collection of common programming errors

Ok, stupid question, I guess…

I’m trying to do this:

File: pt.php


File: index.php


But this doesn’t work (Notice: Undefined variable: lang and langlist).

What am I doing wrong?

P.S.: I know using echo instead of return inside a function ins’t correct, but I don’t want do be using echo __(); every time I need to use this function…

  1. $lang and $langlist are global variables, but they cannot be seen from within the function. Simply add the following as the first line of the function to gain access to them:

    global $lang, $langlist;
    

    Alternatively, you could access them as $GLOBALS['lang'] and $GLOBALS['langlist'] without using the global declaration.

  2. Your syntax is wrong:

    
    

    should be

    
    

Originally posted 2013-11-09 19:11:59.