Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 −
$value1=10; $value2=0;
We need to compare the above 2 variable values.
Example
<!DOCTYPE html> <html> <body> <?php $value1=10; $value2=0; $data=550000; $output=$value1 ? $value2 : $value2 ? : $data; echo "The value is=",$output; ?> </body> </html>
This will produce the following output
Output
The value is=550000
Advertisements
