Welcome Guest, Not a member yet? Register   Sign In
Need advice on code segment...
#1

[eluser]Unknown[/eluser]
Hello everyone.

What is a more efficient way of writing this code:

if ($this->agent->is_mobile('iphone')) {
$this->data['model'] = 'iphone';
}

Also, would it be better to store result in session rather than global variable?

Thanks in advance.
#2

[eluser]boltsabre[/eluser]
The code is fine... there is no more "efficient" way (in terms of "meaningful more than 0.0001 seconds worth" of processing time).

If your interested in ternary operators, check this link out.
http://www.lizjamieson.co.uk/9/short-if-...nt-in-php/
http://davidwalsh.name/javascript-shorth...e-examples

They do have their time and place, but they do make your code less readable and harder to bug hunt, so I wouldn't opt for them just for the sake of it - they still process the "if" and "else" statement, so yeah, they are not more "efficient" in terms of processing time as such.

Quote:Also, would it be better to store result in session rather than global variable?
Yeah, session or cookie would be the way I'd go (I think... it really depends on what you want it for...)
#3

[eluser]Unknown[/eluser]
Thanks for your reply. Pays to check sometimesSmile




Theme © iAndrew 2016 - Forum software by © MyBB