php如何把一个数组中的键名合并到键值中?

大哥,打扰一下,php如何把一个数组中的键名合并到键值中??

同时保持键名不变
foreach ($k.$c as $cv) {echo $c;}
foreach ($c[k].$c[v] as $c[v]) {echo $c;}
都不对
最新回答
当恨能成忧

2024-09-29 00:26:00

<?php
$test = array("key1"=>"value1","key2"=>"value2","key3"=>"value3");
foreach($test as $key=>$value){
$test[$key] = $key.$value;
}
foreach($test as $key=>$value){
echo $key,":",$value,"<br/>";
}
?>
将输出
key1:key1value1
key2:key2value2
key3:key3value3
顽皮捣蛋小精灵

2024-09-29 00:15:57

<?php
$arr["tmp1"]="value1";
$arr["tmp2"]="value2";

foreach( $arr as $key => $val ){
$arr[$key] = $key . "|" . $val ;
}
print_r($arr);
?>