PHP's array_map including keys

前端 未结 18 2729
抹茶落季
抹茶落季 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:10

    With PHP5.3 or later:

    $test_array = array("first_key" => "first_value", 
                        "second_key" => "second_value");
    
    var_dump(
        array_map(
            function($key) use ($test_array) { return "$key loves ${test_array[$key]}"; },
            array_keys($test_array)
        )
    );
    

提交回复
热议问题