[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Help breaking down a this php code

Posted on 2012-03-17
2
Medium Priority
?
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
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

650 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