ChadNomad Posted November 19, 2007 Share Posted November 19, 2007 Hey. I've just started using the ternary operator to shorten my code and make it more readable. I'm curious to know if you can have more than one result returned and how (if you can). I've currently got this: $password == $passwordConfirm ? $valid[3] = 1 : $valid[3] = 0; I'd like to add $vError++ as well in the "else" part if it's possible. Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted November 19, 2007 Share Posted November 19, 2007 Even if you could (which I don't think you can) I would'nt recommend it. Its going to make your code that much more difficult to follow. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 19, 2007 Share Posted November 19, 2007 How would you ever "return" more than 1 result. Do you mean you want to perform more than 1 action per operator section? e.g. $password == $passwordConfirm ? $valid[3] = 1 AND $valid[7] = true : $valid[3] = 0; (btw the above code is nonsense, before you try it) If you want to do that you need to use an if statement, or two ternary statements. $result1 = $password == $passwordConfirm ? $valid[3] = 1 : $valid[3] = 0; $result2 = $password == $passwordConfirm ? $valid[7] = "my var" : $valid[7] = 0; OR if($password == $passwordConfirm){ $valid[3] = 1; $valid[7] = "my var"; } else { $valid[3] = 0; $valid[7] = 0; } Quote Link to comment Share on other sites More sharing options...
ChadNomad Posted November 19, 2007 Author Share Posted November 19, 2007 Do you mean you want to perform more than 1 action per operator section? e.g. $password == $passwordConfirm ? $valid[3] = 1 AND $valid[7] = true : $valid[3] = 0; (btw the above code is nonsense, before you try it) I did mean that. Also why is it nonsense? AND works fine... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.