Benn Benn - 6 months ago 67
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

:hover
and another with
:focus


$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
$newelements = array_map(function($x){ return $x . ':hover'; }, $elements);