array_walk with Class Level Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

array_walk with Class Level Function

Post by TryAgain2 »

From inside a class, can array_walk() take a class level function as an argument? I know it can call a function outside of the class, but that seems untidy.

Code: Select all

class SomeClass
{

	private function sortIntoLists($value, $key)
	{
		echo  "Key $key Value $value <br />";
	}

	private function processText()
	{
		// Break the text into a word array with the index as their positions
		$this->mArrayAllWords = str_word_count($this->mTextForAnalysis, 2);

		// Walk through the array and sort the words into the appropriate lists		
		array_walk($this->mArrayAllWords,  "sortIntoLists"); // **** Function does not exist! ****
                  }
}
I also tried "\$this->sortIntoLists" and "$this->sortIntoLists" with the same error message.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

array_walk($this->mArrayAllWords,  array($this, 'sortIntoLists') );
TryAgain2
Forum Newbie
Posts: 17
Joined: Tue Jun 12, 2007 10:05 pm

Post by TryAgain2 »

Thanks Volka
Post Reply