Jump to content

Archived

This topic is now archived and is closed to further replies.

alecjw

Globals

Recommended Posts

Is it possible to define a variable ,then later on declare it global?

eg:
<?php
$var="hello!";
//some code
global $var;

Share this post


Link to post
Share on other sites
You only really need to use the global keyword from within functions anyway, but to answer your question, yes.

[code=php:0]
<?php

  $var="hello!";

  function foo() {
    global $var;
    echo $var;
  }

  foo();

?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.