mcaskill/php-oneof

Returns the first argument that is set and non-empty.

v1.0.0 2018-09-10 01:47 UTC

This package is not auto-updated.

Last update: 2024-03-21 19:30:10 UTC


README

(PHP 5 >= 5.6)
oneof — Returns the first argument that is set and non-empty.

Description

mixed oneof( mixed $... )

This function returns the first argument that is set and non-empty.

It will guess where to stop based on the types of the arguments, e.g. "" has priority over array() but not 1.

Based on Alex Suraci's oneof() function. Updated for PHP 5.6.

Parameters

  • ... — One or more variables to be checked.

Return Values

Returns the first argument that is set and non-empty.

Examples

Example #1 oneof() example

$created_at = null;
$updated_at = '2005-04-06';

echo 'Created At: '. oneof($created_at, date('Y-m-d')) ."\n";
echo 'Updated At: '. oneof($updated_at, null) ."\n";

The above example will output:

Created At: 2005-03-30
Updated At: 2005-04-06

Installation

With Composer

$ composer require mcaskill/php-oneof

Without Composer

Why are you not using composer? Download Function.OneOf.php from the gist and save the file into your project path somewhere.