Jump to content

make function more efficient


RobinTibbs

Recommended Posts

ok heres the 411 ( or w/e these kids say nowadays ). in all their wisdom, Apple put the safari build numbers in the UserAgent string rather than the actual version numbers, but thankfully they have a table up on their developer site detailing which build numbers refer to which version numbers. to this extent i made this function:

[code]function getSafariVersion($buildstring) {
  if($buildstring == "419.3") {
      return "2.0.4";
  } 
  elseif($buildstring == "417.9.3" | $buildstring == "417.9.2" | $buildstring == "417.8") {
      return "2.0.3";
  }
  elseif($buildstring == "416.13" | $buildstring == "416.12") {
      return "2.0.2";
  }
  elseif($buildstring == "412.5") {
      return "2.0.1";
  }
  elseif($buildstring == "412.2.2" | $buildstring == "412.2" | $buildstring == "412") {
      return "2.0";
  }
  elseif($buildstring == "312.6" | $buildstring == "312.5") {
      return "1.3.2";
  }
  elseif($buildstring == "312.3.1" | $buildstring == "312.3") {
      return "1.3.1";
  }
  elseif($buildstring == "312") {
      return "1.3";
  }
  elseif($buildstring == "125.12" | $buildstring == "125.11") {
      return "1.2.4";
  }
  elseif($buildstring == "125.9") {
      return "1.2.3";
  }
  elseif($buildstring == "125.8" | $buildstring == "125.7") {
      return "1.2.2";
  }
  elseif($buildstring == "100.1") {
      return "1.1.1";
  }
  elseif($buildstring == "100") {
      return "1.1";
  }
  elseif($buildstring == "85.8.1" | $buildstring == "85.8") {
      return "1.0.3";
  }
  elseif($buildstring == "85.7") {
      return "1.0.2";
  }
  elseif($buildstring == "85.5") {
      return "1.0";
  }
}[/code]

was just wondering if there was a more efficient way of going about it? hmm. many thanks in advance
Link to comment
Share on other sites

Can switch statements have multiple items per case, like in the IF statements above

elseif($buildstring == "85.8.1" | $buildstring == "85.8") {
      return "1.0.3";
  }

Would you have to split that into 2 case's? That would make the switch very long...
Link to comment
Share on other sites

Personally, I find switch'es to be easier to read instead of a lot of elseif's. But, there's also another possibility which you might consider. Create an array of the values. Then you dont even need a function:

[code]$SafariVersion['419.3']  = '2.0.4';
$SafariVersion['417.9.3'] = '2.0.3';
$SafariVersion['417.9.2'] = '2.0.3';
$SafariVersion['417.8']   = '2.0.3';
$SafariVersion['416.13']  = '2.0.2';
$SafariVersion['416.12']  = '2.0.2';
[/code]

Then just get your version like this:
[code]echo 'The safarri version is: ' . $SafariVersion[$buildstring];[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.