HookedOnWeb Posted March 14, 2006 Share Posted March 14, 2006 Can someone please help me better understand this line of code?$summary = ($conf['app']['prefixNameOnSummary']) ? "{$rs['fname']} {$rs['lname']}\n " . htmlspecialchars($rs['summary']) : htmlspecialchars($rs['summary']);I understand these are variables:$summary$conf['app']['prefixNameOnSummary']$rs['fname']$rs['lname']$rs['summary']I understand that \n is a new line.I understand what the "." is doing.I understand what htmlspecialchars is doing to $rs['summary'].What I don't understand is this syntax:$summary = () ? "prints the variables between the quotes" . variable : variableWhat is the ? and : for and why is the variable before and after the colon?I understand that the '.' joins the part between the quotes to the $variable : $variableCan someone please tell me what this function is called so that I can look it up and understand how it works? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 14, 2006 Share Posted March 14, 2006 As pulled from this (http://us3.php.net/manual/en/language.expressions.php) page in the manual:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator:[code]<?php$first ? $second : $third?>[/code]If the value of the first subexpression is TRUE (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.[/quote]EDIT:Also, see this page:[a href=\"http://us3.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary\" target=\"_blank\"]http://us3.php.net/manual/en/language.oper...parison.ternary[/a] Quote Link to comment Share on other sites More sharing options...
HookedOnWeb Posted March 14, 2006 Author Share Posted March 14, 2006 Thank you so much that really helped me out. 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.