Jump to content

Archived

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

redarrow

what is this for ? in the middle of codes.

Recommended Posts

i have seen meny people useing this format of programming but what does the ? do cheers.

advance thank you.

this code an example with the ? in the syntex i would like to know what it does incase it is inportant and i am missing somethink here?
[code]
<?php

if(isset($record['name'] ? $record['password'])){

do some think

}
?>
[/code]

Share this post


Link to post
Share on other sites
I think you are referring to the ternary operator, which has the format

$var = ($some_condition) ? $value_if_condition_true : $value_if_false ;

which is shorthand for

[code]
if ($some_condition) {
    $var = $value_if_condition_true;
}
else {
    $var = $value_if_false;
}
[/code]

Share this post


Link to post
Share on other sites
I use it when I am naming one var on the outcome
for example to check a page number

$page_num = is_numeric($_GET["page"] ? $_GET["page"] : 1;
$page_num = str_len($_GET["page"] <= 3 ? $page_num : 1;

Basicly, what you can put in the if statement
if(statement){
can go there
Argument ?(then) :(else)

Share this post


Link to post
Share on other sites

×

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.