-1

I am wondering about returning value to a parameter instead of using =

example of "normal" way how to get return value

function dummy() {
    return false;
}

$var = dummy();

But I am looking for a method how to associate return value without using =, like preg_match_all()

function dummy($return_here) {
    return false;
}
dummy($var2);
var_dump($var2); //would output BOOLEAN(FALSE)

I am sure it has something to do with pointers but in preg_match_all() I never send any pointer to variable or am I mistaken?

preg_match_all('!\d+!', $data, $matches); // I am sending $matches here not &$matches

//I didn't know what to search for well it is simple CALL BY REFERENCE

Kyslik
  • 7,921
  • 5
  • 55
  • 86
  • ok, right away in doc I linked to, there is a function declaration like `int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] )` The most important part is `&$matches`... – Kyslik Jan 05 '14 at 11:16

2 Answers2

2

Use references

i.e.

function dummy(&$return_here) {
    $return_here = false;
}
dummy($var2);
var_dump($var2);
Ed Heal
  • 57,599
  • 16
  • 82
  • 120
2

It is CALL BY REFERENCE:

function dummy(&$var) { //main difference is in this line
    $var = false;
}

dummy($var);
Reza Mamun
  • 5,653
  • 1
  • 39
  • 40