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.
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>

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