forceArray

Definition

1
Arr::forceArray(mixed $var, int $flag = self::FORCE_ARRAY_ALL): mixed
Copied!

Description

Make variable an array (according to flag settings)

Examples

1
Arr::forceArray(0) -> [0]
2
Arr::forceArray('test') -> ['test']
3
4
Arr::forceArray(null) -> [null]
5
Arr::forceArray(null, Arr::FORCE_ARRAY_PRESERVE_NULL) -> null
6
7
8
$object = new stdClass();
9
10
Arr::forceArray($object) -> [$object]
11
// With this flag all objects remain intact
12
Arr::forceArray($object, Arr::FORCE_ARRAY_PRESERVE_OBJECTS) -> $object
13
14
15
$object = new ArrayObject();
16
17
Arr::forceArray($object) -> [$object]
18
// With this flag objects implementing ArrayAccess remain intact
19
Arr::forceArray($object, Arr::FORCE_ARRAY_PRESERVE_ARRAY_OBJECTS) -> $object
Copied!
Last modified 2yr ago
Copy link