Fastest way to add prefix to array keys?

Posted by Kirzilla on Stack Overflow See other posts from Stack Overflow or by Kirzilla
Published on 2010-04-09T13:01:46Z Indexed on 2010/04/09 16:53 UTC
Read the original article Hit count: 131

Filed under:
|

Hello,

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

was

$array = array(
 '1' => 'val1',
 '2' => 'val2',
);

needed

$array = array(
  'prefix1' => 'val1',
  'prefix2' => 'val2',
);

According to http://www.phpbench.com/ (see Modify Loop) I should use "for" statement, but probably there is more elegant way?

Thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays