Jump to content


Photo

what is this for ? in the middle of codes.


  • Please log in to reply
3 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 September 2006 - 11:01 AM

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?
<?php

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

do some think

}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 10 September 2006 - 11:16 AM

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

if ($some_condition) {
     $var = $value_if_condition_true;
}
else {
     $var = $value_if_false;
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 September 2006 - 11:17 AM

Thank you i get it cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 10 September 2006 - 11:48 AM

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)
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users