473,385 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiple choices .. if / else

What do they call something like this ...

<?=(($data->link_place == "T") ? "Top bar":"Main menu bar")?>

... it's sort of a if /else statement. But what if there are three possiblities

T = Top bar
M = Main menu bar
N = No menu


Would I have to use a normal if / ifelse / else statment?
Nov 1 '09 #1

✓ answered by Markus

@entangled
Yes.

What do they call something like this ...

<?=(($data->link_place == "T") ? "Top bar":"Main menu bar")?>

... it's sort of a if /else statement.
That is known as the conditional/ternary operator.

Mark.

3 2089
Markus
6,050 Expert 4TB
@entangled
Yes.

What do they call something like this ...

<?=(($data->link_place == "T") ? "Top bar":"Main menu bar")?>

... it's sort of a if /else statement.
That is known as the conditional/ternary operator.

Mark.
Nov 1 '09 #2
Thanks Mark. The link was very help too ... in my case, according to the link, with PHP, the above statement would turn into:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $arg = "T";
  3. $link_place= ($arg == 'T') ? 'Top bar' :
  4.           (($arg == 'S') ? 'Main menu bar' :
  5.           'Not in menu'));
  6. echo $link_place;
  7. ?>
Nov 1 '09 #3
Markus
6,050 Expert 4TB
@entangled
Yes, but I wouldn't write it as such because it isn't too easy to read, whereas the following is easy to read:

Expand|Select|Wrap|Line Numbers
  1. switch ($arg) {
  2.     case 'T': $link_place = 'Top bar';
  3.         break;
  4.     case 'S': $link_place = 'Main menu bar';
  5.         break;
  6.     default: $link_place = 'Not in menu';
  7.         break;
  8. }
Nov 2 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to...
5
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
2
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie....
4
by: Dj87 | last post by:
Hi, I do not know whether was already posted a request about this problem, but my problem is this. I'd like to insert in a text field of a table of Ms Access some values from a list with the...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
0
by: robert | last post by:
I installed the C# snippets that were recently made available by Microsoft. Since then when I right-click and choose either Insert Snippet or Surround With... or press ctrl space, choose a snippet...
9
by: toton | last post by:
Hi, I am looking for a circular buffer solution ( a fixed buffer) , where the elements can be pushed back & removed front. It looks stl deque can be a solution. my question is, 1) circular...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.