2


i am building a class and it contains some methods

in some method i tried to use [array_map][1] function and make it's $callback a method which is defined inside the same class so i tried

array_map('$this->something()',$this->somearray);

but it didn't work ! and caused this error

function '$this->something' not found or invalid

any ideas to use an internal method in the class as a callback ?

1
  • If you're using PHP >= 5.3 then just use a closure. Commented Nov 24, 2012 at 21:48

1 Answer 1

1

If you're using PHP >= 5.3 then just use a closure.

array_map(function($a) {}, $this->somearray);

Otherwise it should be:

array_map(array($this, 'something'), $this->somearray);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.