Print the keys of an array

前端 未结 8 707
旧巷少年郎
旧巷少年郎 2020-11-27 21:07

I could not figure out how to pass a variable number of variables into a function. I thought passing in an array and using the array keys for the variables names could repla

8条回答
  •  生来不讨喜
    2020-11-27 21:20

    If you want just to output keys, you can do this without cycles:

    $parameters = ["day" => 1, "month" => 8, "year" => 2010];
    echo  implode('
    ', array_keys($parameters));

    Or output keys with values:

    $parameters = ["day" => 1, "month" => 8, "year" => 2010];
    echo implode('
    ', array_map(function($v, $k){ return $k.'='.$v;}, $parameters, array_keys($parameters)));

提交回复
热议问题