Skip to content

Instantly share code, notes, and snippets.

@blar
Created June 30, 2014 19:35
Show Gist options
  • Select an option

  • Save blar/a82bfb5619bb785e149b to your computer and use it in GitHub Desktop.

Select an option

Save blar/a82bfb5619bb785e149b to your computer and use it in GitHub Desktop.
array_map
<?php
$array = array(
'foo' => 23,
'bar' => 42
);
$result = array_map(function($value) {
return $value * 2;
}, $array);
var_dump($result);
$result = array_map(function($value, $index) {
return $index.': '.$value;
}, $array, array_keys($array));
var_dump($result);
array(2) {
["foo"]=>
int(46)
["bar"]=>
int(84)
}
array(2) {
[0]=>
string(7) "foo: 23"
[1]=>
string(7) "bar: 42"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment