Re: how to insert html code with PHP
| From: | Jim Giner | Date: | Thu, 11 Apr 2013 17:19:20 +0000 |
| Subject: | Re: how to insert html code with PHP | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-320828@lists.php.net to get a copy of this message | ||
On 4/11/2013 10:48 AM, Rafnews wrote:
On 11.04.2013 13:34, Rafnews wrote:function xxxx() { global $submenu; ... ... }Hi, I would like to insert a piece of HTML code inside several pages. all pages are differently named. i need in each page to find a particular tag, let's say <div id="#submenu">...</div> (so based on its ID and tagname) and inside it to insert my PHP/HTML code. how can i do that ? thx. A.Ok i can write an include_once('myfile.php'); however if i have an array in this file, other files where is the include_once(); do not recognize the array. here is an extract of this file to include (submenu.php): <?php $submenu = array(); $submenu[] = array('id' => 1,'class'=>'menuitem1'); $submenu[] = array('id' => 2,'class'=>'menuitem2'); // function in the same file function DisplayMenu($title){ // here i do not have access to the previous array $submenu define outside the function ... } as it is included the function DisplayMenu should also have access to $submenu array, no ? basic php question. Variables within any function are local to that function (except for superglobals like $_POST, $_SESSION, etc.). In order to reference a var defined/used outside that function you must add a global statement in the function: