I am a straight novice in PHP. So, please do not down vote my question as it may seem very silly. I have a code to check if a number is greater than another number in php.
if($num1 > $num2)
{
echo $num1
}
else
{
echo $num2
}
The above code is the exact one in my file. But no output is being shown. Any help will be appreciated.
The max() function of PHP is used to find the numerically maximum value in an array or the numerically maximum value of several specified values. The max() function can take an array or several numbers as an argument and return the numerically maximum value among the passed parameters.
The max() function returns the highest value in an array, or the highest value of several specified values.
$min = min($numbers); $max = max($numbers); Option 2. (Only if you don't have PHP 5.5 or better) The same as option 1, but to pluck the values, use array_map : $numbers = array_map(function($details) { return $details['Weight']; }, $array);
The easiest way to do that is:
echo max($num1, $num2);
John, the answer is very simple. You have not added a ;
at the end of your statement. Change your code to the following :-
if($num1 > $num2)
{
echo $num1;
}
else
{
echo $num2;
}
This code will surely work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With