It's basically a combination of explode()
, array_map()
and join()
:
join('|', array_map(function($item) {
return end((explode('-', $item)));
}, explode('|', $str)));
The inner explode()
creates an array of all items between pipes from the given string, the array_map()
takes the last piece of each dash delimited sub string and the final join()
stitches them all together.