note 40135 deleted from function.array-filter by nlopess
| From: | nlopess@php.net | Date: | Mon, 23 Feb 2004 09:37:29 +0000 |
| Subject: | note 40135 deleted from function.array-filter by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65576@lists.php.net to get a copy of this message | ||
Note Submitter: steven at xinu dot org
----
An anonymous fellow tried to provide an example of using a class method as the callback for
array_filter() and confused it toward the end by changing the method name. Here's a
straightforward code snippet:
<?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);
}
}
?>