note 40133 added to function.array-filter
| From: | stevenatxinudotorg at rn2 dot php dot net | Date: | Mon, 23 Feb 2004 05:39:47 +0000 |
| Subject: | note 40133 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65560@lists.php.net to get a copy of this message | ||
The anonymous fellow a few posts up was trying to illustrate how to use the array_filter() function
with class methods but confused things a bit. Here's a cleaner example:
<?php
class testclass
{
function testclass()
{
// define the numbers array
$numbers = array(1, 2, 3, 4, 5, 6);
// pull out the odd numbers
$odd = array_filter($numbers, array($this, "odd"));
// pull out the even numbers
$even = array_filter($numbers, array($this, "even"));
}
function odd($var)
{
return($var % 2 == 1);
}
function even($var)
{
return($var % 2 == 0);
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40133
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40133&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40133&report=yes
Search -- http://master.php.net/manage/user-notes.php