Forums

variable scope (3 posts)

  1. jbbrwcky
    Member
    Posted 6 years ago #

    I'm working in the index.php which calls various other bits in the theme. At the top, to randomize I declare...

    srand((double)microtime()*1000000);
    $randval = rand(0,1);

    ... inside <?php ?> section. If I want to use it later on in the same file, I can still call $randvall without having to declare srand again right?

    Jbbrwcky

  2. Firas
    Member
    Posted 6 years ago #

    As long as you're not within a function or something like that, sure. If you're curious about what the value is of $randval somewhere just do <?php var_dump($randval); ?>. If it turns out empty, do <?php global $randval; ?> before you use it.

  3. jbbrwcky
    Member
    Posted 6 years ago #

    Thanks firas!

Topic Closed

This topic has been closed to new replies.

About this Topic