Oihana PHP

core

Table of Contents

Namespaces

accessors
arrays
date
documents
helpers
json
maths
numbers
objects
reflections
strings

Functions

ifNull()  : mixed
Returns the given value if it is not null; otherwise, returns the default value.
isLiteral()  : bool
Checks whether a given value is a literal string representing a boolean (`true` or `false`) or `null`.

Functions

ifNull()

Returns the given value if it is not null; otherwise, returns the default value.

ifNull(mixed $value[, mixed $default = null ]) : mixed

This function is useful to provide a fallback value when a variable might be null.

Parameters
$value : mixed

The value to evaluate.

$default : mixed = null

The default value to return if $value is null. Defaults to null.

Tags
example
echo ifNull(null, 'default');   // Outputs: default
echo ifNull('hello', 'default'); // Outputs: hello
echo ifNull(0, 'default');       // Outputs: 0 (because 0 is not null)
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
mixed

Returns $value if it is not null; otherwise returns $default.

isLiteral()

Checks whether a given value is a literal string representing a boolean (`true` or `false`) or `null`.

isLiteral(mixed $value) : bool

This function returns true only if the value is a string and equals (case-insensitive) to one of the three literal values: "true", "false", or "null".

Parameters
$value : mixed

The value to test.

Tags
example
isLiteral('true');   // true
isLiteral('False');  // true
isLiteral('null');   // true
isLiteral('yes');    // false
isLiteral(true);     // false
isLiteral(null);     // false
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

Returns true if the value is a string and matches "true", "false", or "null" (case-insensitive).


        
On this page

Search results