toArray.php
Table of Contents
Functions
- toArray() : array<int|string, 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<int|string, mixed>
If the value is already an array, it is returned unchanged. Otherwise, the value is wrapped inside a new array.
⚠️ This function wraps : toArray( null ) answers [ null ], a list
holding one item. When a value of unknown shape has to be read as a record or
a list — and what is not an array must become nothing to read — reach for
arrayOrEmpty() instead, which answers []. The two read almost the
same at a call site and behave in opposite ways.
Parameters
- $value : mixed
-
The value to encapsulate in an array.
Tags
Return values
array<int|string, mixed> —The value wrapped in an array, or the original array if already an array.