Link to home
Start Free TrialLog in
Avatar of GamesNET2
GamesNET2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

php simplification question

Hi there,

Does anyone know how I could simplify the code below? It's not easily expandable how it is at the moment -

Thanks!


<?php if ($count == 1 or $count == 4 or $count == 7 ) : 
echo "testimonial_1" ;
elseif ($count == 2 or $count == 5 or $count == 8) : 
echo "testimonial_2" ;
elseif ($count == 3 or $count == 6 or $count == 9) :
echo "testimonial_3"; 
 endif ?>

Open in new window

Avatar of gamebits
gamebits
Flag of Canada image

switch($count){

      case '1':

              echo "testimonial_1" ;
break;

    case '2':

              echo "testimonial_2" ;
break;

    case '3':

           echo "testimonial_3" ;
break;

     case '4'

          echo "testimonial_1" ;
break;

}

you can expand as much as you want on this.
Hi there, you could also reduce it to the following

 
switch($count){

      case '1':
      case '4':
      case '7':

        echo "testimonial_1" ;
        break;

    case '2':
    case '5':
    case '8':

        echo "testimonial_2" ;
        break;

    case '3':
    case '6':
    case '9':

       echo "testimonial_3" ;
       break;

}

Open in new window


--TheDoctor
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GamesNET2

ASKER

Exactly what I was after! thanks,