For any complex processing you could always create a function to return the ID that you want to return, and then echo the result of the function, something like:
<?php
function getId($vm, $showRightColumn) {
if ($vm->check("pagetype = cart")) {
return $showRightcolumn ? 'contentarea2' : 'newcontentarea';
}
return $showRightColumn ? 'contentarea2' : 'contentarea';
}
?>
<div id="<?php echo getId($vm, $showRightColumn); ?>">...</div>
However, for simpler conditionals, it may just be better to use a ternary operator which evaluates other ternary statements (as suggested by other answers).