php - Conditional Check -
i trying make conditional code dependent on if user has left or right bar disabled. have following
<?php $left_sidebar = 'off'; $right_sidebar = 'on'; if ($left_sidebar == 'on' || $right_sidebar == 'on') { $left_sidebar_width = 'four_columns'; $right_sidebar_width = 'four_columns'; $center_width = 'eight_columns'; } else if ($left_sidebar == 'on' || $right_sidebar == 'off') { $left_sidebar_width = 'four_columns'; $right_sidebar_width = 'disabled'; $center_width = 'twelve_columns'; } else if ($left_sidebar == 'off' || $right_sidebar == 'on') { $left_sidebar_width = 'disabled'; $right_sidebar_width = 'four_columns'; $center_width = 'twelve_columns'; } else { $left_sidebar_width = 'disabled'; $right_sidebar_width = 'disabled'; $center_width = 'sixteen_columns'; } echo $left_sidebar_width; echo '<br />'; echo $right_sidebar_width; echo '<br />'; echo $center_width; echo '<br />'; ?>
the problem have no matter change $left_sidebar or $right_sidebar says
four_columns four_columns eight_columns
what doing wrong makes not change when turn 1 of sidebars off?
because have:
$left_sidebar = 'off'; $right_sidebar = 'on';
and using "or" logical operator, match first if
statement because $right_sidebar
on
. change "or" ||
operator "and" &&
, should expected results.
if ($left_sidebar == 'on' && $right_sidebar == 'on') { $left_sidebar_width = 'four_columns'; $right_sidebar_width = 'four_columns'; $center_width = 'eight_columns'; } else if ($left_sidebar == 'on' && $right_sidebar == 'off') { $left_sidebar_width = 'four_columns'; $right_sidebar_width = 'disabled'; $center_width = 'twelve_columns'; } else if ($left_sidebar == 'off' && $right_sidebar == 'on') { $left_sidebar_width = 'disabled'; $right_sidebar_width = 'four_columns'; $center_width = 'twelve_columns'; } else { $left_sidebar_width = 'disabled'; $right_sidebar_width = 'disabled'; $center_width = 'sixteen_columns'; }
Comments
Post a Comment