If elseif else or ternary operator to compare numbers PHP?

You can use any of them, but a more professional approach is using the ternary operator (?). Performance of both if-else and ternary operator is the same.

Let’s say we have the following two variable values −


We need to compare the above 2 variable values.


 Live Demo

<!DOCTYPE html>
$output=$value1 ? $value2 : $value2 ? : $data;
echo "The value is=",$output;

This will produce the following output


The value is=550000