Created
October 13, 2016 09:03
-
-
Save ishideo/624c1b3e8b1087d0ebace290d32643d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$record = [ | |
["id" => "1", | |
"name" => "東京都", | |
"alias" => "東京", | |
], | |
["id" => "2", | |
"name" => "神奈川県", | |
"alias" => "神奈川"], | |
["id" => "3", | |
"name" => "埼玉県", | |
"alias" => "埼玉"], | |
["id" => "4", | |
"name" => "千葉県", | |
"alias" => "千葉"], | |
]; | |
$func = function($value) { | |
return [$value['id'] => $value['alias']]; | |
}; | |
$func2 = function ($result, $item) { | |
if ($result == NULL) { $result = []; } | |
$result = $result + $item; | |
return $result; | |
}; | |
$pref_array = array_map($func, $record); | |
$pref_name = array_reduce($pref_array, $func2); | |
print_r($pref_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment