user8333817
user8333817

Reputation:

Is there a neater way to do this - php max()

Quick question hopefully, more curious of neatness than a problem here.

I am wanting to change a variable to another value only if the other value is, for example, larger than the original...

Eg.

if ($x < $y) $x = $y;

Or a neater way of doing this seems to be:

$x = max($x, $y);

My question is, is this (the latter) the best way. Or is there a neater way? Thanks, S

Upvotes: 1

Views: 53

Answers (1)

Saqib Malik
Saqib Malik

Reputation: 98

The quicker and neatest method is:

$x = max($x, $y);

hope it answered your question

Upvotes: 2

Related Questions