
Skip to main content
If statement with multiple conditions in php
You can use if statement with multiple conditions within single if statement or you can also use if statement with elseif and else condition in php.
-
If statement with OR (||) condition in php
$var = "abc"; if($var == "abc" || $var == "def") { echo "true"; }
It will return true if the value of $var is abc or def. If the value we assign to $var is not equal to “abc” or “def” then the if statement will not be executed.
-
If statement with AND (&&) condition in php
if($var == "abc" && $var2 == "def") { echo "true"; }
It will return true if both conditions are true like if the value of $var is abc and the value of $var2 is def. If any of the values of these two variables is not equal to the passed value after the (==) operator then the if statement will not be executed.
-
If statement with elseif and else condition in PHP
<?php $records = ['first', 'second', 'third']; if (count($records) === 1){ echo "I have one record! "; } elseif (count($records) > 1) echo "I have multiple records!"; else{ echo "I don't have any records!"; } ?>
Bootstrap
Cmd
CodeIgniter
Css
Drupal
Git
Html
Javascript
Jquery
Laravel
Nodejs
Php
Python
Sql
Typescript
Wordpress
Random Code Snippet Queries: Php
- How to displaying ckeditor save HTML data from SQL database
- Shorthand for isset() in php
- User-defined functions in php
- Required parameter $originalDate follows optional parameter $format
- How to get image tmp_name in PHP
- How to get date with day, month, year, weekdays from string "2021/08/12" in php
- How to check If an element exists in Array in php
- How to add new item to array in PHP
- PHP number format indian currency
- Delay code execution in PHP
- How to display data in ckeditor?
- You are trying to access an array as object
- Page view counter in PHP
- Show errors in php
- Convert string to sha512 in PHP
- How to check file is an image in php
- How to increment variable value by 1 in php
- Convert comma-separated string into array in PHP
- How to remove duplicate values from Array in PHP
- Array to string conversion error in PHP
- Get the first key of an array in php
- Convert an array to string in PHP