> For the complete documentation index, see [llms.txt](https://arrayutils.docs.present.kim/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://arrayutils.docs.present.kim/methods/c/flat.md).

# flat()

{% code title="Example.php" %}

```php
<?php use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from([
    [1, 2, 3],
    [[4, 5, 6], [7, 8, 9]],
    10
]);

//To flat single level array
$arrayUtils->flat();
// expected output: [1, 2, 3, [4, 5, 6], [7, 8, 9], 10]

//To flat two level array
$arrayUtils->flat(2);
// expected output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
```

{% endcode %}

## Syntax

```php
$arrayUtils->flat(int $dept = 1) : ArrayUtils;
```

### Parameter

* `$dept` <img src="/files/-MKk9YjCz_YkVR1YiRy-" alt="" data-size="line">&#x20;
  * The depth level that should be flattened.\
    Default is `1`.

### Return value

* A new array with the sub-array elements concatenated into it.

## Prefixing

```php
$arrayUtils->flatAs(int $dept = 1) : array;
```

```php
ArrayUtils::flatFrom(iterable $from, int $dept = 1) : ArrayUtils;
```

```php
ArrayUtils::flatFromAs(iterable $from, int $dept = 1) : array;
```

## References

{% embed url="<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat>" %}
