PHP 的 array_map 包括鍵 - PHP's array_map including keys

問題:

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_keysarray_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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章