php如何使用数组简化代码

php如何使用数组简化代码,php,arrays,if-statement,echo,Php,Arrays,If Statement,Echo,我有以下一段php代码: <?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_

我有以下一段php代码:

<?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';
}
?>

从本质上说,若排版设置为小回音12、标准回音13、大回音14、大回音15

我知道这段代码工作得很好,但我想学习如何使用数组,我想知道这段代码是否可以通过使用数组来简化?

不是火箭科学:

$font_sizes = array(
    'small' => 12,
    'standard' => 13,
    ...
);

$size = get_theme_mod('typography_setting');
if( isset($font_sizes[$size]) ){
    echo $font_sizes[$size];
}
您还可以更频繁地使用Enter键来增强代码。

非火箭科学:

$font_sizes = array(
    'small' => 12,
    'standard' => 13,
    ...
);

$size = get_theme_mod('typography_setting');
if( isset($font_sizes[$size]) ){
    echo $font_sizes[$size];
}

您还可以通过更大量地使用Enter键来增强代码。

根据您的条件,它应该是切换caseuse in_array(),根据您的条件,它应该是切换caseuse in_array()