3v4l.org

run code in 500+ PHP versions simultaneously
<?php $res_events = "|2,20171021|1,20171007|2,20171007|1,20171028|2,20171014|1,20171014|2,20171028|1,20171021|"; $arr = explode("|", $res_events); Sort($arr); // Remove one of the two empty values in array Unset($arr[0]); // Implode and add last "|" $new =implode("|", $arr)."|"; Echo $new;

preferences:
43.09 ms | 1694 KiB | 5 Q