redarrow Posted September 10, 2006 Share Posted September 10, 2006 i have seen meny people useing this format of programming but what does the ? do cheers.advance thank you.this code an example with the ? in the syntex i would like to know what it does incase it is inportant and i am missing somethink here?[code]<?phpif(isset($record['name'] ? $record['password'])){do some think}?>[/code] Link to comment https://forums.phpfreaks.com/topic/20282-what-is-this-for-in-the-middle-of-codes/ Share on other sites More sharing options...
Barand Posted September 10, 2006 Share Posted September 10, 2006 I think you are referring to the ternary operator, which has the format$var = ($some_condition) ? $value_if_condition_true : $value_if_false ;which is shorthand for[code]if ($some_condition) { $var = $value_if_condition_true;}else { $var = $value_if_false;}[/code] Link to comment https://forums.phpfreaks.com/topic/20282-what-is-this-for-in-the-middle-of-codes/#findComment-89296 Share on other sites More sharing options...
redarrow Posted September 10, 2006 Author Share Posted September 10, 2006 Thank you i get it cheers. Link to comment https://forums.phpfreaks.com/topic/20282-what-is-this-for-in-the-middle-of-codes/#findComment-89297 Share on other sites More sharing options...
onlyican Posted September 10, 2006 Share Posted September 10, 2006 I use it when I am naming one var on the outcomefor example to check a page number$page_num = is_numeric($_GET["page"] ? $_GET["page"] : 1;$page_num = str_len($_GET["page"] <= 3 ? $page_num : 1;Basicly, what you can put in the if statementif(statement){can go thereArgument ?(then) :(else) Link to comment https://forums.phpfreaks.com/topic/20282-what-is-this-for-in-the-middle-of-codes/#findComment-89300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.