Matt Ridge
Matt Ridge

Reputation: 3651

Is it smart to put these three variables into a function or an array?

I want to take these:

$xp = '(Windows NT 5.1)';
$vista = '(Windows NT 6.0)';
$win7 = '(Windows NT 6.1)';

And put it into a function win{}.

Basically I want it so that if a person is using a windows' OS the output would be $win so I can then use it as an if else listing...

Or would I be better off using this in an array?

Is this possible? I know it may sound confusing so I am sorry if it is, I really don't know how to explain this correctly.

Upvotes: 0

Views: 89

Answers (3)

Jeremy Harris
Jeremy Harris

Reputation: 24549

I'm not sure about the exact platform results available when calling get_browser, but this should be close:

$win = Array('WinXP','WinVista','Win7');
$browser = get_browser(null, true);
if(array_search($browser['platform'],$win))
{
   echo('The user is using ' . $browser['platform'] . 'and it is contained in my array.');
}

Determine client OS in PHP

Upvotes: 2

Dan Blows
Dan Blows

Reputation: 21174

Yes, use an array. Otherwise when Windows 8 comes out, you'll need to add new code.

Even better code a dedicated function - something like isWindows - which receives a string and returns a Boolean based on whether the string contains Windows. Then, how you actually do the detection is contained within the function.

Upvotes: 1

Francis Lewis
Francis Lewis

Reputation: 8980

Instead of putting them into an array, if you don't need the exact version of windows the person is using, I would run something like a strpos to see if windows exists in their user agent.

If you do need to know the exact version they're using, I would recommend putting them in a key => value pair array since you'll have a lot more versions of windows than that.

Upvotes: 1

Related Questions