Q:

displaying items in array ordered by id inside string

I want to display items in an array separately, ordered by groups. 
The items are stored in a string like this:
$itemsString = "1:asd, 1:wer, 2:dfg, 3:gfg, 3:sdfss"; //and so forth

Then I display them like this: 
$itemsArray = explode(", ", $itemsString);
foreach($itemsArray as $item){
 echo substr($item,2); //substr to get rid of the group id
}

EDIT: solution
if(strpos($item, "1:")!==false){
echo substr($item,2);
}

A:

You could perform another explode on your initial array on the colon, seperate the number and the value, then feed them into a array using the number as the key, eg:
$itemsString = "1:asd, 1:wer, 2:dfg, 3:gfg, 3:sdfss"; //and so forth

$sorted_array = [];
$itemsArray = explode(", ", $itemsString);
foreach($itemsArray as $item) {
    $subItemsArray = explode(":", $item);
    $sorted_array[$subItemsArray[0]][] = $subItemsArray[1];
}

print_r($sorted_array);

Which would mean $sorted_array would be pre-sorted for you (or easily sortable with ksort()):
Array
(
    [1] => Array
        (
            [0] => asd
            [1] => wer
        )

    [2] => Array
        (
            [0] => dfg
        )

    [3] => Array
        (
            [0] => gfg
            [1] => sdfss
        )

)

