The following code shows an example of Using Nested If in PHP.
As can be seen in the following code, we use the nested-if statement to find the largest of four numbers.
<?php
echo '<h1>Example Demonstrating Nested-if Statement in PHP</h1>';
echo '<h2>Find Largest of four numbers: [31, 12, 90, 56]</h2>';
$a=31;
$b=12;
$c=90;
$d=56;
if($a>$b)
{
if($a>$c)
{
if($a>$d)
{
echo '<h2>'.$a.' is Largest!</h2>';
}
else
{
echo '<h2>'.$d.' is Largest!</h2>';
}
}
else
{
if($c>$d)
{
echo '<h2>'.$c.' is Largest!</h2>';
}
else
{
echo '<h2>'.$d.' is Largest!</h2>';
}
}
}
else
{
if($b>$c)
{
if($b>$d)
{
echo '<h2>'.$b.' is Largest!</h2>';
}
else
{
echo '<h2>'.$d.' is Largest!</h2>';
}
}
else
{
if($c>$d)
{
echo '<h2>'.$c.' is Largest!</h2>';
}
else
{
echo '<h2>'.$d.' is Largest!</h2>';
}
}
}
?>
Output

Further Reading
Examples of Array Functions in PHP
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML