i'm new to php. I came across this syntax in wordpress. Can anyone explain to me the last line of that code?
$page = $_SERVER['REQUEST_URI'];
$page = str_replace("/","",$page);
$page = str_replace(".php","",$page);
**$page = $page ? $page : 'default'**
the last line(bolded).
thanks
...
Is there a ?: operator equivalent in .net?
eg in java I can do:
retParts[0] = (emailParts.length > 0) ? emailParts[0] : "";
rather than
if (emailParts.length > 0) {
retParts[0] = emailParts[0];
} else {
retParts[0] = "";
}
I'd like to be able to do similar in VB.NET.
...
I kept my hands off Delphi for too long, I guess; busied myself with Java and PHP a lot over the last couple of years. Now, when I got back to doing a little Delphi job, I realised I really miss the conditional operator which is supported by both Java and PHP.
On how many places would you find lines like these in your Delphi programs?
...
I have two collections, and items that are added to one or the other of those collections based on whether some criteria is met.
Somewhat inadvertantly, I stumbled on the fact that it is legal to write
(test(foo) ? cOne : cTheOther).add(foo);
instead of
if (test(foo)) {
cOne.add(foo);
} else {
cTheOther.add(foo);
}
While the fir...
Possible Duplicate:
What is the PHP ? : operator called and what does it do?
From http://twitto.org/
<?PHP
require __DIR__.'/c.php';
if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; }))
throw new Exception('Error');
$c();
?>
Twitto uses several new features available as of PHP 5.3:
The DIR constant
The ...
Can you make an assignment on conditional statement in php as so:
if(siteName_err = isValid("sitename", $_POST['sitename'], false))
{
$siteName = $_POST['sitename'];
}
...
I'm a little stumped by this little C# quirk:
Given variables:
Boolean aBoolValue;
Byte aByteValue;
The following compiles:
if (aBoolValue)
aByteValue = 1;
else
aByteValue = 0;
But this will not:
aByteValue = aBoolValue ? 1 : 0;
Error says: "Cannot implicitly convert type 'int' to 'byte'."
And of course, this monstr...
Is there any benefit to structuring boolean expressions like:
if (0 < x) { ... }
instead of
if (x > 0) { ... }
I have always used the second way, always putting the variable as the first operand and using whatever boolean operator makes sense, but lately I have read code that uses the first method, and after getting over the initia...
I was looking at some code with a huge switch statement and an if-else statement on each case and instantly felt the urge to optimize. As a good developer always should do I set out to get some hard timing facts and started with three variants:
The original code looks like this:
public static bool SwitchIfElse(Key inKey, out char key,...
I am familiar with standard zipWith functions which operate on corresponding elements of two sequences, but in a functional language (or a language with some functional features), what is the most succinct way to conditionally select the pairs of elements to be zipped, based on a third sequence?
This curiosity arose while scratching o...
So for binary operators on booleans, Java has &, |, ^, && and ||.
Let's summarize what they do briefly here:
JLS 15.22.2 Boolean Logical Operators &, ^, and |
JLS 15.23 Conditional-And Operator &&
JLS 15.24 Conditional-Or Operator ||
For &, the result value is true if both operand values are true; otherwise, the result is false....
Possible Duplicate:
Conditional operator cannot cast implicitly?
When writing a statement using the conditional operator, if the either of the expressions are numeric values they are always interpreted as int type. This makes a cast necessary to assign a short variable using this operator.
bool isTrue = true;
int intVal = is...
I can't seem to find what I need on google, and bet I'll get quick answer here.
String str;
bool b = true;
b ? str="true" : str="false";
Console.Out.WriteLine(str);
that ? : syntax looks correct to me. I'm getting compiler error though.
Program.cs(13,28):
error CS1002: ; expected
Program.cs(13,28):
error CS...
This question is hard to phrase, so I'm going to have to use some code samples. Basically, I have an (overloaded) method that takes 3 parameters, the last of which I overloaded. As in, sometimes the last parameter is a String, sometimes it's a double, etc. I want to call this method using a ternary conditional expression as the last para...
Possible Duplicates:
Nullable types and the ternary operator. Why wont this work?
Conditional operator assignment with nullable<value> types?
This will not compile, stating "Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTime' and ''"
task.ActualEndDate = Text...
I have a simple little code fragment that is frustrating me:
HashSet<long> groupUIDs = new HashSet<long>();
groupUIDs.Add(uid)? unique++ : dupes++;
At compile time, it generates the error:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
HashSet.Add is documented to return a bool...
I want to perform some action ONLY IF my string has a meaningful value. So, I tried this.
if (!myString.equals("")) {
doSomething
}
and this
if (!myString.equals(null)) {
doSomething
}
and this
if ( (!myString.equals("")) && (!myString.equals(null))) {
doSomething
}
and this
if ( (!myString.equals("")) && (myString!=null)) {
do...
I'm a bit puzzled about the conditional operator. Consider the following two lines:
Float f1 = false? 1.0f: null;
Float f2 = false? 1.0f: false? 1.0f: null;
Why does f1 become null and the second statement throws a NullPointerException?
Langspec-3.0 para 15.25 sais:
Otherwise, the second and third operands are of types S1 and S2...
I am calling three functions in my code where i want to validate some of my fields.
When I tries to work with the code given below. It checks only for first value until it gets false result.
I want some thing like that if fisrt function returns true then it should also call next function and so on. What can be used instead of Or Operato...
Hi everyone,
Quick question here about short-circuiting statements in C#. With an if statement like this:
if (MyObject.MyArray.Count == 0 || MyObject.MyArray[0].SomeValue == 0)
{
//....
}
Is it guaranteed that evaluation will stop after the "MyArray.Count" portion, provided that portion is true? Otherwise I'll get a null exception...