PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Fri Feb 20, 2004 1:57 am
hey guys, i use them alot, but only by recognition that i need them not because i know what they do or mean:
Code: Select all
<?php
$subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
?>
What do the "?" and ":" mean in this example?
Thanks.
Dr Evil
Forum Contributor
Posts: 184 Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland
Post
by Dr Evil » Fri Feb 20, 2004 2:16 am
This is short syntax for if...else.
Code: Select all
<?php
$subject = ( !empty($subject) ) ? preg_replace($orig_word, $replace_word, $subject) : '';
//is equal but shorter to
if (!empty($subject){
$subject=preg_replace($orig_word, $replace_word, $subject)
}
else{
// do nothing
}
?>
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Fri Feb 20, 2004 7:21 am
Is that all? nothing else?
Dr Evil
Forum Contributor
Posts: 184 Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland
Post
by Dr Evil » Fri Feb 20, 2004 8:05 am
Well it's a nice way of making things more compact. But that is all I know.
Were you expecting anymore ?
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Feb 20, 2004 9:28 am
evilcoder wrote: Is that all? nothing else?
Yep, that's all they are.
evilcoder
Forum Contributor
Posts: 345 Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia
Post
by evilcoder » Fri Feb 20, 2004 7:47 pm
no thats cool. Just wondering, thanks heaps for replying, appreciate it alot.
Have a good day guys.