Usephul

functions.php

Tags
author

Alwin Garside alwin@garsi.de

copyright

2025 The Empaphy Project

license

MIT

Table of Contents

Functions

array_interchange()  : array<string|int, mixed>
Interchange the values of two elements of an array.
is_closed_resource()  : mixed
Finds whether the given variable is a {@link https://www.php.net/types.resource resource} that has been closed.
is_zero()  : bool
Finds whether the given number is (sufficiently close to) 0.
seq()  : Generator<string|int, string|int>
Sequences a value into a {@see \Generator}.
uses()  : bool
Checks whether an object or class uses a given trait.

Functions

array_interchange()

Interchange the values of two elements of an array.

array_interchange(array<string|int, mixed> $array, TKey $key1, TKey $key2) : array<string|int, mixed>

If a key doesn't exist in the array, then the other key will be set to null, and a warning will be thrown.

Parameters
$array : array<string|int, mixed>
$key1 : TKey
$key2 : TKey
Return values
array<string|int, mixed>

is_closed_resource()

Finds whether the given variable is a {@link https://www.php.net/types.resource resource} that has been closed.

is_closed_resource(T $value) : mixed
Parameters
$value : T

The variable being evaluated.

Return values
mixed

Returns true if value is a resource variable that has been closed, false otherwise.

is_zero()

Finds whether the given number is (sufficiently close to) 0.

is_zero(int|float $value[, float|null $tolerance = PHP_ZERO_TOLERANCE ]) : bool
Parameters
$value : int|float

The number being evaluated.

$tolerance : float|null = PHP_ZERO_TOLERANCE

Tolerance allowed when evaluating the number.

Return values
bool

Returns true if value is (sufficiently close to) 0, false otherwise.

seq()

Sequences a value into a {@see \Generator}.

seq(mixed $value) : Generator<string|int, string|int>
Parameters
$value : mixed

The value to sequence.

Return values
Generator<string|int, string|int>

uses()

Checks whether an object or class uses a given trait.

uses(object|string $object_or_class, string $trait[, bool $allow_string = true ]) : bool
Parameters
$object_or_class : object|string

A class name or an object instance.

$trait : string

The trait name.

$allow_string : bool = true

If this parameter set to false, string class name as object_or_class is not allowed. This also prevents from calling autoloader if the class doesn't exist.

Return values
bool

This function returns true if the object_or_class, or any of its traits, uses trait or if any of its parents, or its parents' traits, use trait.


        
On this page

Search results