{"id":418,"date":"2022-08-30T15:01:01","date_gmt":"2022-08-30T15:01:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/return-an-array-value-from-included-file-in-a-function-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:01:01","modified_gmt":"2022-08-30T15:01:01","slug":"return-an-array-value-from-included-file-in-a-function-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/return-an-array-value-from-included-file-in-a-function-collection-of-common-programming-errors\/","title":{"rendered":"Return an array value from included file in a function-Collection of common programming errors"},"content":{"rendered":"<p>Ok, stupid question, I guess&#8230;<\/p>\n<p>I&#8217;m trying to do this:<\/p>\n<p><strong>File:<\/strong> pt.php<\/p>\n<pre><code>\n<\/code><\/pre>\n<p><strong>File:<\/strong> index.php<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>But this doesn&#8217;t work (Notice: Undefined variable: lang and langlist).<\/p>\n<p>What am I doing wrong?<\/p>\n<p><strong>P.S.:<\/strong> I know using <code>echo<\/code> instead of <code>return<\/code> inside a function ins&#8217;t correct, but I don&#8217;t want do be using <code>echo __();<\/code> every time I need to use this function&#8230;<\/p>\n<ol>\n<li>\n<p><code>$lang<\/code> and <code>$langlist<\/code> 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:<\/p>\n<pre><code>global $lang, $langlist;\n<\/code><\/pre>\n<p>Alternatively, you could access them as <code>$GLOBALS['lang']<\/code> and <code>$GLOBALS['langlist']<\/code> without using the <code>global<\/code> declaration.<\/p>\n<\/li>\n<li>\n<p>Your syntax is wrong:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>should be<\/p>\n<pre><code>\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:11:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Ok, stupid question, I guess&#8230; I&#8217;m trying to do this: File: pt.php File: index.php But this doesn&#8217;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&#8217;t correct, but I don&#8217;t want do be using echo __(); every time I need [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-418","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=418"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}