Search
 
SCRIPT & CODE EXAMPLE
 

PHP

null coalescing operator example in php

$name = $_GET['name'] ?? $_POST['name'] ?? 'nobody';
//it is equavelent to below conditions

if (isset($_GET['name'])) {
 $name = $_GET['name'];
} elseif (isset($_POST['name'])) {
 $name = $_POST['name'];
} else {
 $name = 'nobody';
}
Comment

?? Null Coalescing Operator PHP

<?php
// Example usage for: Null Coalesce Operator
$action = $_POST['action'] ?? 'default';

// The above is identical to this if/else statement
if (isset($_POST['action'])) {
    $action = $_POST['action'];
} else {
    $action = 'default';
}
?>
Comment

php null coalesce

// if $_POST['name'] doesn't exist $result will equal to John
$result = $_POST['name'] ?? 'John';
Comment

PREVIOUS NEXT
Code Example
Php :: laravel Auth::logoutOtherDevices 
Php :: define php 
Php :: create a laravel project 
Php :: Set a minimum subtotal amount in Woocommerce cart 
Php :: wordpress autoload composer 
Php :: php upload multiple files 
Php :: Difference in seconds between datetime 
Php :: Show all laravel valet folders 
Php :: php try json decode and check 
Php :: symfony messenger conf 
Php :: export mysql data to word in php 
Php :: How do I change the URL of Add to cart in WooCommerce 
Php :: force https redirect php s 
Php :: mysql Cannot pass parameter 2 by reference 
Php :: dependable validation in laravel 
Php :: php function to remove null or 0 value from array 
Php :: display money format php 
Php :: template string php 
Php :: get return value from another function laravel 
Php :: signup form in php 
Php :: php count string in array 
Php :: parse json phph 
Php :: php key_exists 
Php :: how to save and get checkbox value in database php 
Php :: integer data type php 
Php :: laravel blade if else condition 
Php :: wordpress query get results 
Php :: laravel migration column types 
Php :: how to go one folder back in __dir__ in php 
Php :: php get last day of month 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =