Arkane Posted November 6, 2008 Share Posted November 6, 2008 Hey folks I'm trying to teach myself some PHP, and I've managed to make a working script with arguments in the url. So far I have file.php?name=Leroux I'm looking to change it to have a secondary argument which is optional. eg file.php?name=Leroux&lives=UK I know how to do it as a required, but my method tends to break it if the parameter isnt there. Any suggestions? Cheers guys Link to comment https://forums.phpfreaks.com/topic/131638-optional-arguments/ Share on other sites More sharing options...
rhodesa Posted November 6, 2008 Share Posted November 6, 2008 <?php if(isset($_GET['lives'])){ $lives = $_GET['lives']; }else{ $lives = 123; //Default value } echo $lives; ?> or shorthand: $lives = isset($_GET['lives']) ? $_GET['lives'] : 123; Link to comment https://forums.phpfreaks.com/topic/131638-optional-arguments/#findComment-683703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.