Fastest way to add prefix to array keys?

后端 未结 9 1502
迷失自我
迷失自我 2020-11-28 14:29

What is the fastest way to add string prefixes to array keys?

Input

$array = array(
 \'1\' => \'val1\',
 \'2\' => \'val2\',
);
<
9条回答
  •  孤街浪徒
    2020-11-28 14:39

    Another way to do achieve is with array_flip()

     &$val) { $val = "prefix" . $val; }
        $data = array_flip($data);
    

提交回复
热议问题