問題:
Is there a way of doing something like this:有沒有辦法做這樣的事情:
$test_array = array("first_key" => "first_value",
"second_key" => "second_value");
var_dump(array_map(function($a, $b) { return "$a loves $b"; },
array_keys($test_array),
array_values($test_array)));
But instead of calling array_keys
and array_values
, directly passing the $test_array
variable?但是不是調用array_keys
和array_values
,而是直接傳遞$test_array
變量?
The desired output is:所需的輸出是:
array(2) {
[0]=>
string(27) "first_key loves first_value"
[1]=>
string(29) "second_key loves second_value"
}
解決方案:
參考一: https://stackoom.com/question/shIe參考二: PHP's array_map including keys