Jump to content


Photo

Globals


  • Please log in to reply
2 replies to this topic

#1 alecjw

alecjw
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationHatfield, Herts, UK

Posted 06 August 2006 - 10:08 PM

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

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 06 August 2006 - 10:13 PM

You only really need to use the global keyword from within functions anyway, but to answer your question, yes.

<?php

  $var="hello!";

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

  foo();

?>


#3 alecjw

alecjw
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationHatfield, Herts, UK

Posted 06 August 2006 - 10:14 PM

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users