Solved

if else ? : notation

Posted on 2014-03-23
6
227 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 31

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

863 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

18 Experts available now in Live!

Get 1:1 Help Now