Jump to content

Can you put an if statement within a return?


jason360

Recommended Posts

You can either use the ternary operator to do an in-line condition, or just split the return across two branches of a normal if/else.

 

if ($a > $b){
   return 'a is bigger than b';
}
else {
   return 'a is less than or equal to b';
}
or

return ($a > $b)?'a is bigger than b':'a is less than or equal to b';

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.