The Bat Posted May 30, 2008 Share Posted May 30, 2008 Hello, I find myself using quite a bit of (example): function say_greeting($greeting = null) { $greeting = ($greeting) ? $greeting : 'Hello!' echo $greeting; } in my code (return $greeting if set, otherwise return 'Hello!'), and it's certainly not very DRY. In Ruby, a simple: def say_greeting(greeting = nil) print greeting || 'Hello!' end does the trick. I'm wondering if I can do something similar in PHP instead of what I am doing? Thanks! Link to comment https://forums.phpfreaks.com/topic/107916-question-about-in-php/ Share on other sites More sharing options...
trq Posted May 30, 2008 Share Posted May 30, 2008 The ternary operator is as close as your going to get in php I'm afraid. Link to comment https://forums.phpfreaks.com/topic/107916-question-about-in-php/#findComment-553179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.