Q:

what the best way to write this without repeating myself

A php file is going to receive a variable between 1 and 30 from a form using
 $style = $_GET['style'];

i want to then pass $style to help me choose the css stlye the user has selected so for example if the choice is style 3 then css stlye three will be passed to an image like this
<img style="<?php $choice3?>";  src="xxx.png" />

so what i have so far is this
<?php
 $style = $_GET['style'];

function choice1()
{
$choice1 = "display: block;padding:5px; etc, etc etc";
      return $choice1;      }   
function choice2()
{
$choice2 = "display: block;padding:10px; etc, etc etc";
    return $choice2;        }   
function choice3()
{
$choice3 = "display: block;padding:20px; etc, etc etc";
    return $choice3;        }   

if ($style == 1){
?>
<img style="<?php $choice1?>";  src="xxx.png" />
<?php 
}
if ($style == 2){
?>
<img style="<?php $choice2?>";  src="xxx.png" />
<?php 
}
.......and so on till 30        
?>                  

I am pretty sure there is an easier smarter way to convey my logic.

A:

How about an array? Don't forget to check that $style is in the proper range before using the code below.
<?php
$style = $_GET['style'];
$styles = array(
  1=>"display: block;padding:5px; etc, etc etc",
  2=>"display: block;padding:15px; etc, etc etc",
  3=>"display: block;padding:35px; etc, etc etc",
  4=>"display: block;padding:55px; etc, etc etc",
  // etc.
);
?>

<img style="<?php echo $styles[$style]; ?>";  src="xxx.png" />

