Styling and activating radio buttons on condition I have some php code to style a button and activate it, when a specific variable is true.
It's actually a radio button, styled with the bootstrap to a button.
As you can see below, this is how it looks when the variable is '1'.
Also, the buttons at the bottom are the same, but then with one extra option.
The HTML code for this is the following:
    
                    Navigation bar color:
                    

                &lt;?php

                    if ($navcolor == '1') {
                        $nav_color_i_active  = 'active';
                        $nav_color_i_checked = 'checked';
                        $nav_color_n_active  = '';
                        $nav_color_n_checked = '';
                    } else {
                        $nav_color_i_active  = '';
                        $nav_color_i_checked = '';
                        $nav_color_n_active  = 'active';
                        $nav_color_n_checked = 'checked';
                    }
                ?&gt;

                &lt;div class="btn-group" data-toggle="buttons"&gt;
                    &lt;label class="btn btn-primary &lt;?= $nav_color_i_active ?&gt;"&gt;
                        &lt;input type="radio" name="navcolor" value="1" &lt;?= $nav_color_i_checked ?&gt;&gt; Inverted
                    &lt;/label&gt;
                    &lt;label class="btn btn-primary &lt;?= $nav_color_n_active ?&gt;"&gt;
                        &lt;input type="radio" name="navcolor" value="0" &lt;?= $nav_color_n_active ?&gt;&gt; Normal
                    &lt;/label&gt;

                &lt;/div&gt;




&lt;div class="form-group"&gt;
&lt;label&gt;Navigation bar position:
                    &lt;/label&gt;

                    &lt;?php
                        if ($navpos == '2') {
                            $nav_pos_2_active  = 'active';
                            $nav_pos_2_checked = 'checked';
                            $nav_pos_1_active  = '';
                            $nav_pos_1_checked = '';
                            $nav_pos_0_active  = '';
                            $nav_pos_0_checked = '';
                        } elseif ($navpos == '1') {
                            $nav_pos_2_active  = '';
                            $nav_pos_2_checked = '';
                            $nav_pos_1_active  = 'active';
                            $nav_pos_1_checked = 'checked';
                            $nav_pos_0_active  = '';
                            $nav_pos_0_checked = '';
                        } else {
                            $nav_pos_2_active  = '';
                            $nav_pos_2_checked = '';
                            $nav_pos_1_active  = '';
                            $nav_pos_1_checked = '';
                            $nav_pos_0_active  = 'active';
                            $nav_pos_0_checked = 'checked';
                        }
                    ?&gt;

                    &lt;div class="btn-group" data-toggle="buttons"&gt;
                        &lt;label class="btn btn-primary &lt;?= $nav_pos_2_active ?&gt;"&gt;
                            &lt;input type="radio" name="navpos" value="2" &lt;?= $nav_pos_2_checked ?&gt;&gt; Floating
                        &lt;/label&gt;
                        &lt;label class="btn btn-primary &lt;?= $nav_pos_1_active ?&gt;"&gt;
                            &lt;input type="radio" name="navpos" value="1" &lt;?= $nav_pos_1_active ?&gt;&gt; Sticky to top
                        &lt;/label&gt;
                        &lt;label class="btn btn-primary &lt;?= $nav_pos_0_active ?&gt;"&gt;
                            &lt;input type="radio" name="navpos" value="0" &lt;?= $nav_pos_0_active ?&gt;&gt; Dynamic, stick to top
                        &lt;/label&gt;

                    &lt;/div&gt;

                &lt;/div&gt;



As you can see, it's a lot of code for not a lot of buttons. I've used empty variables, because otherwise php would return errors, for unknown variables.
Is it possible that this code can look a lot cleaner, and that there can be less code?
Firstly, you could shorten the names of the variables e.g from $nav_color_i_active to $i_active and so on.
Secondly, there is a problem in your logic. You see else part will run if $navcolorhas any value other than 1. You should use elseif instead of else in both parts of code.