Solved

Help breaking down a this php code

Posted on 2012-03-17
2
190 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 500 total points
Comment Utility
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 82

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now