note 110247 modified in function.array-filter by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Dec 2012 15:00:15 +0000 |
| Subject: | note 110247 modified in function.array-filter by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192355@lists.php.net to get a copy of this message | ||
You can use array_filter from within a class to access a protected method from that same class:
<?php
class Bar {
public function foo()
{
$array1 = array("a"=>1, "b"=>2, "c"=>3,
"d"=>4, "e"=>5);
print_r(array_filter($array1, array($this, 'naz')));
}
protected function baz($var)
{
return($var & 1);
}
}
$bar = new Bar();
$bar->foo();
?>
--was--
You can use array_filter from within a class to access a protected method from that same class:
<?php
class Bar {
public function foo()
{
$array1 = array("a"=>1, "b"=>2, "c"=>3,
"d"=>4, "e"=>5);
print_r(array_filter($array1, array($this, 'naz')));
}
protected function baz($var)
{
return($var & 1);
}
}
$bar = new Bar();
$bar->foo();
http://php.net/manual/en/function.array-filter.php