- var_dump: documentation ( source)
<?php
class Person
{
var $name;
var $age;
function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}
}
$a = new ArrayIterator([
new Person("Christoph", 15),
new Person("John", 42),
new Person("Foobar", 25)
]);
function first_match(\Iterator $iterator, callable $callback)
{
foreach ($iterator as $key => $value) {
if ($callback($value, $key)) {
yield $key => $value;
break;
}
}
}
$firstOver18 = function($person) {
return $person->age >= 18;
};
var_dump(first_match($a, $firstOver18)->current());