Benn Benn - 10 months ago 138
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?

$newelements = array_map(function($x){ return $x . ':hover'; }, $elements);