0

what is the meaning of this line? Can any body help me? I have confusion on last 2 sign :'' why without this two sign browser make error? Thanks all.

isset($_POST['but'])? $_POST['but']:'';
jeroen
  • 91,079
  • 21
  • 114
  • 132
cms
  • 106
  • 8

5 Answers5

1

U use the tenary comparison operator

A ternary operator have value for true and false

($contidition) ? true : false;

Please refer php documentation about ternary operator comparison operator

In case of:

isset( $_POST['but'] ) ? $_POST['but'] : ''

What it mean is, when $_POST['but'] exist, use it, otherwise use empty string

If u use php version > 5.3 u can use something like

isset($_POST['but']) ? : ''
slier
  • 6,511
  • 6
  • 36
  • 55
0

If $_POST request body contains but parameter - use it, overwise use empty string.

If you are misunderstood statement ? something : anything code - it's the Ternary Operator

Alex
  • 11,115
  • 12
  • 51
  • 64
0

It's nothing but the Ternary Operator

Explanation: If your $_POST['but'] is set , then it will assign the same value to it , else it will set a ''

A clear example here

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Well it's called an ternary operator.

Example:

$value = 5;
($value > 2) ? true : false; // returns true

The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE, and expr3 if expr1 evaluates to FALSE.

(isset($_POST['but'])) ? $_POST['but']:'';

Here if your value $_POST['but'] is set then it will return $_POST['but'] else it will return ''.

Joke_Sense10
  • 5,341
  • 2
  • 18
  • 22
0

It's just another way to write if/else statement. For example:

$but = isset($_POST['but'])? $_POST['but']:'';

Would be the same as:

if(isset($_POST['but'])){
$but= $_POST['but'];
}else{
$but = '';
}
meda
  • 45,103
  • 14
  • 92
  • 122