Skip to content

Instantly share code, notes, and snippets.

@wowo
Created December 8, 2010 08:35
Show Gist options
  • Save wowo/733039 to your computer and use it in GitHub Desktop.
Save wowo/733039 to your computer and use it in GitHub Desktop.
Quick question to check PHP 5.3 knowledge
<?php
$guys[] = "Robert, age 24";
$guys[] = "Alice, age 19";
$guys[] = "Jacob, age 29";
array_walk($guys, function (&$guy) {
$guy = preg_replace_callback("#^\w{2}\w+#", function($value) {
$value = current($value);
for ($i = 2; $i < strlen($value); $i++) {
$value[$i] = "#";
}
return $value;
}, $guy);
});
while (list(, $value) = each($guys)) {
printf("%s\n", $value);
}
//what will be output of above scrip?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment