PHP's array_map including keys

前端 未结 18 2771
抹茶落季
抹茶落季 2020-11-30 19:31

Is there a way of doing something like this:

$test_array = array(\"first_key\" => \"first_value\", 
                    \"second_key\" => \"second_valu         


        
18条回答
  •  猫巷女王i
    2020-11-30 20:20

    Based on eis's answer, here's what I eventually did in order to avoid messing the original array:

    $test_array = array("first_key" => "first_value",
                        "second_key" => "second_value");
    
    $result_array = array();
    array_walk($test_array, 
               function($a, $b) use (&$result_array) 
               { $result_array[] = "$b loves $a"; }, 
               $result_array);
    var_dump($result_array);
    

提交回复
热议问题