Oihana PHP

toArray.php

Table of Contents

Functions

toArray()  : array<string|int, mixed>
Ensures the given value is returned as an array.

Functions

toArray()

Ensures the given value is returned as an array.

toArray(mixed $value) : array<string|int, mixed>

If the value is already an array, it is returned unchanged. Otherwise, the value is wrapped inside a new array.

Parameters
$value : mixed

The value to encapsulate in an array.

Tags
example
use function oihana\core\arrays\toArray;

$a = toArray(123);
print_r($a); // [123]

$b = toArray("hello");
print_r($b); // ["hello"]

$c = toArray([1, 2, 3]);
print_r($c); // [1, 2, 3]

$d = toArray(null);
print_r($d); // [null]
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
array<string|int, mixed>

The value wrapped in an array, or the original array if already an array.


        
On this page

Search results