Skip to content

Instantly share code, notes, and snippets.

@ephrin
Last active December 17, 2015 14:49
Show Gist options
  • Save ephrin/5626797 to your computer and use it in GitHub Desktop.
Save ephrin/5626797 to your computer and use it in GitHub Desktop.
Test of test v0.2
$array = array('_0' => 0);
$array = new ArrayHelper($array);
$func = function ($key, $value, ArrayHelperInterface $array) {
static $i;
$i++;
$c = count($array);
if (is_string($key) && $c < $value) {
unset($array[$key]);
return true;
} else {
$array['_'.$i] = --$c;
return false;
}
};
$array->each($func);
var_dump(iterator_to_array($array));
/*
array(2) {
'_0' =>
int(0)
'_1' =>
int(0)
}
*/
$array->some($func);
var_dump(iterator_to_array($array));
/*
array(4) {
'_0' =>
int(0)
'_1' =>
int(0)
'_2' =>
int(1)
'_3' =>
int(2)
}
*/
$array->every($func);
var_dump(iterator_to_array($array));
/*
array(5) {
'_0' =>
int(0)
'_1' =>
int(0)
'_2' =>
int(1)
'_3' =>
int(2)
'_4' =>
int(3)
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment