Solved

if else ? : notation

Posted on 2014-03-23
6
226 Views
Last Modified: 2014-03-23
<?php echo (isset($pageTitle)) ? $pageTitle : 'Some Content Site';

Open in new window


I still can not conceptualize this example

if page isset use pagetitle else some content site
0
Comment
Question by:rgb192
6 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 350 total points
ID: 39948756
Yes, is the ternary operator(http://www.php.net/ternary)

It is as you wrote:
if (isset($pageTitle))
{
  echo $pageTitle;
}
else
{
  echo 'Some Content Site';
}

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39948782
::No points for this::

I still can not conceptualize this example

if page isset use pagetitle else some content site


You answered your own question ;o)
0
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 150 total points
ID: 39948826
That notation is some sadist's idea of shortening his code.   Don't use it, all it does is complicate something that should be straightforward, and make code unreadable.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 58

Expert Comment

by:Gary
ID: 39948843
Really, I use it all the time.
0
 

Author Closing Comment

by:rgb192
ID: 39948936
Gary wrote: no points.

Now, I understand if else better and may/mayNot use this
0
 
LVL 58

Expert Comment

by:Gary
ID: 39948941
There should only be one answer and that is Marco's nothing else answered your question.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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