GregL83 Posted April 26, 2007 Share Posted April 26, 2007 Simple questions for the noob...I have an if statement where I want true to be returned dependent on three things. The first must always be true and the second and third must have one of the two true...I am not sure how the operation is conducted... if(isset($_POST['submit']) && $item = "width" or $item = "height") { $update["$item"] = $_POST[$item]."px"; } Thanks for the help.. Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/ Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 if(isset($_POST['submit']) && $item = "width" || isset($_POST['submit']) && $item="height"){ $update[$item] = $_POST[$item] . "px"; } Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/#findComment-238671 Share on other sites More sharing options...
btherl Posted April 26, 2007 Share Posted April 26, 2007 You can use brackets to enforce the order of evaluation. Another method is to create temporary variables to hold intermediate results, and then use those temporary variables in the "if". Temporary variables often results in MUCH more readable code. Example: $submitted = isset($_POST['submit']; $item_valid = ($item == "width" or $item == "height"); if ($submitted && $item_valid) { } Also note that you must use == or === when testing values, NEVER =. "=" will set the variable to a new value. Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/#findComment-238673 Share on other sites More sharing options...
GregL83 Posted April 26, 2007 Author Share Posted April 26, 2007 Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/#findComment-238678 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 $submitted = isset($_POST['submit']); * You can also do this: $submit = (isset($_POST['submit'])) ? $_POST['submit'] : NULL; // If submit is set, then $submit is = $submit, else its NULL. if($submit){ if($item == "width" OR $item == "height"){ # do this } } Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/#findComment-238679 Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 like this: <?php if(isset($_POST['submit']) && ($item = "width" || $item = "height")) { $update['$item'] = $_POST[$item'] . 'px'; } ?> Link to comment https://forums.phpfreaks.com/topic/48711-solved-using-and-operator-in-same-line/#findComment-238680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.