Solved

if else ? : notation

Posted on 2014-03-23
6
229 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

789 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