Answers for "php assign if not null"

PHP
6

is null php

// The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.

<?php
    $var = NULL;  
	if (is_null($var)) {
      	echo "yes, is null";
      
    } else {
      	echo "not null";
    }
?>
Posted by: Guest on October-15-2020
0

php assign if not null

// below is assign if null
$final_output = $check_null ?: $default_value;

// assign if not null
$final_output = !($check_null) ?: $default_value;

`Edit`
?: is tenary operator a.k.a one-line if expression
syntax: <if expression null> ?: <do this>
Posted by: Guest on April-08-2022

Browse Popular Code Answers by Language