how to simplify this code I'm just wondering if you see any ways I could simplify the following code without making it too difficult for a newbie to understand what I'm trying to do:

    if (trim($this-&gt;uri-&gt;segment(5)) == 1) {


    if ( $this-&gt;my_model-&gt;functionA($this-&gt;uri-&gt;segment(8),$this-&gt;uri-&gt;segment(4)) )
    {
        $data['light'] =  $this-&gt;my_model-&gt;data();
    }
    else
    {
        show_error($this-&gt;my_model-&gt;errormessage());
    }
    }
    elseif (trim($this-&gt;uri-&gt;segment(5)) == 0) {

      if ( $this-&gt;my_model-&gt;functionB($this-&gt;uri-&gt;segment(8),$this-&gt;uri-&gt;segment(4)) )
      {
          $data['light'] = $this-&gt;my_model-&gt;data();
      }
      else
      {
          show_error($this-&gt;my_model-&gt;errormessage());
      }
    }       
    elseif (trim($this-&gt;uri-&gt;segment(5)) == 2) {

      if ( $this-&gt;my_model-&gt;functionC($this-&gt;uri-&gt;segment(8),$this-&gt;uri-&gt;segment(4)) )
      {

          $data['light'] = $this-&gt;my_model-&gt;data();
      }
      else
      {
          show_error($this-&gt;my_model-&gt;errormessage());
      }        
    }       


I guess I could use a switch statement but i would still need to check the results of each function call.  Would it still be beneficial to use switch?  if so, can you explain why? 

Any suggestions would be appreciated. 
thanks.
I haven't been able to test it, but I'm fairly sure this will work:

$functionName = 'function';
switch(trim($this-&gt;uri-&gt;segment(5)))
{
    case 1: $functionName .= 'A'; break;
    case 0: $functionName .= 'B'; break;
    case 2: $functionName .= 'C'; break;
}
if($this-&gt;my_model-&gt;$functionName($this-&gt;uri-&gt;segment(8), $this-&gt;uri-&gt;segment(4)))
{
    $data['light'] = $this-&gt;my_model-&gt;data();
}
else
{
    show_error($this-&gt;my_model-&gt;errormessage());
}


For more information, see the PHP page on Variable Functions.