0

I have $width and $height, which are random and represent the video's width and height.

If the video dimensions are greater then or equal to 1080p, it will create a 720p, 480p versions of the video, and so on.

If the dimensions are greater then or equal to 720p, it will create a 480p, 360p, and so on.

And this goes on...

I was using the following if statements to do this:

if($width >= 1920 && $height >= 1080)
{
    // create 720p...
}

if($width >= 1280 && $height >= 720)
{
    // create 480p...
}

But I figure that switch statements will be better if I won't use break since if one case is true, it will execute all the other cases below without checking.

Is this the right approach? How would I apply this to a switch statement?

jewishmoses
  • 1,069
  • 2
  • 11
  • 16

1 Answers1

0

Switch block is only for variable value comparison. It doesn't make sense in other cases, especially in your case where you have 2 int variables to compare. If block will do proper job.

You can do the job with switch (see below), but it's prettier with conventional if conditions.

switch (true) {
    case ($width >= 1920 && $height >= 1080): //create 720p
        break;
    case ($width >= 1280 && $height >= 720): //create 480p
        break;
    //...
}
Jsowa
  • 9,104
  • 5
  • 56
  • 60