to_array

Modified on Thu, 9 Jul at 10:49 AM

to_array

TABLE OF CONTENTS

Wrap data in an array

Definition

array[any] to_array(any $data)

Converts $data to an array, unless $data is already an array.

Parameters

any $data

Data to convert into an array.

Returns

array[any]

An array containing $data, except if $data is an array, in which case returns $array.

Examples

Transformation
{
  a: to_array(`null`),
  b: to_array(`1`),
  c: to_array(`text`),
  d: to_array(`{name: 'Jane'}`),
  e: to_array(`[]`),
  f: to_array(`[1, 2, 3]`)
}
Result
{
  "a": [null],
  "b": [1],
  "c": ["text"],
  "d": [{"name": "Jane"}],
  "e": [],
  "f": [1, 2, 3]
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article