Jump to content

[SOLVED] very quick question


nikefido

Recommended Posts

yes...the first part is your conditional statement, then after the ? is if it's true and after the : is if it's false. It's use most to shorten up this case:

 

<?php
if($test > 3){
  $result = 'first case';
}else{
  $result = 'second case';
}
?>

shortened to

<?php
$result = $test > 3 ? 'first case' : 'second case';
?>

<test_expression>?<true_expression>:<false_expression>

 

U use boolean conditional when an expression is required.

$sample = <expression>;

 

just provides a shortcut when u have 2 results based on an expression, and returns either the true expression or false expression depending on the test_expression.

 

if($gender=='m') $display='Male';

else $display='Female';

 

see all the repetition

 

shorten with

$display=($gender=='m'?'Male':'Female')

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.