Forums

How to "save" variable values across functions? (3 posts)

  1. apascal
    Member
    Posted 2 years ago #

    I am trying to save a variable and its value (e.g. $id = 1) across functions. The variable gets its value in Function1, and I would like to use the value in Function 2.

    How can I do this? Thanks so much!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    function one() {
    global $id;
    $id = 1;
    }
    function two() {
    global $id;
    echo $id;
    }
  3. apascal
    Member
    Posted 2 years ago #

    I didn't know you were supposed to declare a variable globally in the first function!

    Thanks a lot :)

Topic Closed

This topic has been closed to new replies.

About this Topic