Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defaulting unset values with out a if Statement

Tags:

php

I think there a easier way to perform the same function but without if statements.

if (isset($_GET['limit']))
 {
  $limit = $_GET['limit'];
 }
else
 {
   $limit = 10;
 }
like image 740
David Allen Avatar asked Nov 23 '25 23:11

David Allen


2 Answers

If there is I'd be open to hearing it...

...But I think your best bet is just a short hand if/else statement instead. Not that it really makes any difference.

$limit = (isset($_GET['limit']) ? $_GET['limit'] :  10;

More info here - http://www.lizjamieson.co.uk/9/short-if-statement-in-php/

like image 200
SpaceBeers Avatar answered Nov 25 '25 16:11

SpaceBeers


short if ?

$limit = isset($_GET['limit']) ? $_GET['limit'] :  10;
like image 43
Haim Evgi Avatar answered Nov 25 '25 16:11

Haim Evgi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!