Benn Benn - 2 years ago 193
PHP Question

Is there a reliable PHP one liner to suffix/prefix array values?

I need to suffix array values which will in fact be a tag CSS, so I need to suffix one array with

and another with

$elements = array('.one','.two','.three');

desired new arrays

$helements = array('.one:hover','.two:hover','.three:hover');
$felements = array('.one:focus','.two:focus','.three:focus');

I know I can do it with a loop but question is, is there a fast one liner for this?

Answer Source
$newelements = array_map(function($x){ return $x . ':hover'; }, $elements);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download