?
Solved

Help breaking down a this php code

Posted on 2012-03-17
2
Medium Priority
?
199 Views
Last Modified: 2012-03-18
Hi All,

I having been getting some help with a custom store that I am building and have been given a piece of code by support that works but I do not understand how and would be grateful if someone could break it down for me.

.(isset($_SESSION['currencySymbol']))?$_SESSION['currencySymbol']:"$".

I understand the isset. So for me this statement says if session "currencySymbol" exists, but I do not know what the ? is for at the end as well as the :"$"
0
Comment
Question by:Lightwalker
2 Comments
 
LVL 17

Accepted Solution

by:
bigeven2002 earned 2000 total points
ID: 37733684
Hello,

The ? : style is a ternary operator which is meant to be shorthand for traditional if statements.

The code above is the same as:
if(isset($_SESSION['currencySymbol']):
    
else:
    $_SESSION['currencySymbol'] = "$";
endif;

Open in new window


So basically, if that SESSION variable is not set, then set it to "$".
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 37733778
What he said.  See Ternary Operator on this page: http://www.php.net/manual/en/language.operators.comparison.php
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question