Reputation: 3697
I have the following piece of php code:
<?php
if(get_theme_mod('typography_setting')=='small')
{
echo '12';
}
else if(get_theme_mod('typography_setting')=='standard')
{
echo '13';
}
else if(get_theme_mod('typography_setting')=='big')
{
echo '14';
}
else if(get_theme_mod('typography_setting')=='huge')
{
echo '15';
}
?>
Essentially saying, if typography setting is small echo 12, standard - echo 13, big - echo 14, huge - echo 15.
I know this code works fine, but I'm wanting to learn about using arrays and I'm wondering if this code can be simplified by using an array?
Upvotes: 1
Views: 85
Reputation: 146578
Not rocket science:
$font_sizes = array(
'small' => 12,
'standard' => 13,
...
);
$size = get_theme_mod('typography_setting');
if( isset($font_sizes[$size]) ){
echo $font_sizes[$size];
}
You can also enhance your code with a more profuse use of the Enter key.
Upvotes: 6