Solved

Help breaking down a this php code

Posted on 2012-03-17
2
195 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 500 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 83

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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.
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.

691 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