user173457
user173457

Reputation: 165

How do I get the return variable from a function inside another function

Using an Excel library, how do I make function check_stuff return false when needed? As of right now, $this->check_stuff($path) always returns true. Keep in mind that I cannot modify class Excel.

private function check_stuff($path) {
    Excel::filter('chunk')->load($path)->chunk(250, function($results) {
    // check something
        return false;
    });

    return true;
}

Upvotes: 1

Views: 33

Answers (2)

Kevin
Kevin

Reputation: 41903

Try to import it in the anonymous function:

private function check_stuff($path) {

    $result = true;
    Excel::filter('chunk')->load($path)->chunk(250, function($results) use (&$result) {
        // check something
        $result = false;
    });

    return $result;
}

Upvotes: 2

kyo
kyo

Reputation: 610

Have you tried this?

private function check_stuff($path) {
  return Excel::filter('chunk')->load($path)->chunk(250, function($results) {
    // check something
    return false;
  });
}

Upvotes: 0

Related Questions