Anyone with a cool example of an instance where a method accepting a block was a good solution for your problems? I think it is pretty neat for things like:
Code:
>> a = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
=> ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
>> a.reject { |x| x.match /o/ }
=> ["red", "green", "blue"]
I guess something similar in PHP would look like
PHP Code:
$a = array('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet');
var_dump(array_filter($a, create_function('$e','return !preg_match("/o/", $e);')));
Bookmarks