Without any special checks, to iterate through the cart items the loop would go like:
foreach($_SESSION['cart'] as $cartId) {
// do something with the $cartId and so on
}
* UPDATE *
If however is a string (as you stated in the comment) you need to explode it first to an array like that:
// if it is like "4,4,4,4,4,4" and not an array
$array = explode(',', $_SESSION['cart']);
foreach($array as $cartId) {
// do something with the $cartId and so on
}