With all due respect, but this is not a proper forum to learn the PHP / WP. If you are going to ask every single thing, the people will grow tired by your question and you won’t receive any answers at all.
Seek help in online forums specialized on PHP / WP programming. There are many private groups on FB as well. Register on StackOverflow, etc. Most importantly, learn to SEARCH for the information online. You are not reinventing the wheel. These are basic things you can easily find answers to online. You just need to put some effort into that. Without putting a lot of the effort you won’t make it as a professional anyway.
However, you can have the best code possible, the design is the most important part. You can always improve the code of the approved theme via updates. But you won’t be approved without a great design.
But to answer your question. I would do it like this (considering this code is inside some sort of template file and not in a function):
<?php if ( ! empty( $theme_options['opt-post-sidebar'] ) && true === $theme_options['opt-post-sidebar'] ) : ?>
<div class="col-xl-9 col-md-9 col-sm-12 col-xs-12">
<?php else : ?>
<div class="col-xl-12 col-md-12 col-sm-12 col-xs-12">
<?php endif; ?>