acctman Posted September 7, 2008 Share Posted September 7, 2008 I'd like to know if this coding is correct, I ran it through a PHP IDE app and no errors were shown. i just want to double check, the second one line code if ($_POST['add_type'] == 1) { $points == 2; } else { $points == 1; } compact way, is this right? $points = ($_POST['add_type']==1) ? 2 : 1; Link to comment https://forums.phpfreaks.com/topic/123174-solved-simplifying-an-if-statement/ Share on other sites More sharing options...
Brandon Jaeger Posted September 7, 2008 Share Posted September 7, 2008 That is correct although you may want to convert it to an integer first. $num = (int)$_POST['add_type']; $points = ($num == 1) ? 2 : 1; Link to comment https://forums.phpfreaks.com/topic/123174-solved-simplifying-an-if-statement/#findComment-636155 Share on other sites More sharing options...
Mchl Posted September 7, 2008 Share Posted September 7, 2008 Second one is OK, first one should be if ($_POST['add_type'] == 1) { $points = 2; } else { $points = 1; } Link to comment https://forums.phpfreaks.com/topic/123174-solved-simplifying-an-if-statement/#findComment-636156 Share on other sites More sharing options...
acctman Posted September 7, 2008 Author Share Posted September 7, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/123174-solved-simplifying-an-if-statement/#findComment-636157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.