Passing variables from a function

Is there a way in PHP to pass variables from a function to the scope in which it was called?
I understand there is return, but I’m interested in just setting an external variable from a function (and besides $GLOBALS).

Answer 1, authority 100%

There are several ways:

  1. Via $GLOBALS. (though you don’t like it)
  2. Via global $param. (for some reason you didn’t like it either)
  3. Via return array('param' => $param)and parse it.
  4. By passing parameters to the function as references: function a(&$param){$param = 123;}.

Did I forget something?

Leave a reply

Please enter your comment!
Please enter your name here