You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== array_insert ==
[[../objects/ms.lang.IndexOverflowException|ms.lang.IndexOverflowException]] |- ! scope="row" | Since | 3.3.1 |- ! scope="row" | Restricted |
Copy Code
The output would be:
Copy Code
The output would be:
Inserts an item at the specified index, and shifts all other items in the array to the right one. If index is greater than the size of the array, an IndexOverflowException is thrown, though the index may be equal to the size, in which case this works just like array_push(). The array must be normal though; associative arrays are not supported.
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| array_insert
|-
! scope="row" | Returns
| void
|-
! scope="row" | Usages
| array, item, index
|-
! scope="row" | Throws
| [[../objects/ms.lang.CastException|ms.lang.CastException]][[../objects/ms.lang.IndexOverflowException|ms.lang.IndexOverflowException]] |- ! scope="row" | Since | 3.3.1 |- ! scope="row" | Restricted |
No
|-
! scope="row" | Optimizations
| None
|}
=== Usages ===
array_insert(array, item, index)=== Examples === ====Example 1==== Basic usage Given the following code:
array @array = array(1, 3, 4);
array_insert(@array, 2, 1);
msg(@array);

1 {{object|array}} @array = {{function|array}}(1, 3, 4);
2 {{function|array_insert}}(@array, 2, 1);
3 {{function|msg}}(@array);
{1, 2, 3, 4}====Example 2==== Usage as if it were array_push Given the following code:
@array = array(1, 2, 3);
array_insert(@array, 4, array_size(@array));
msg(@array);

1 @array = {{function|array}}(1, 2, 3);
2 {{function|array_insert}}(@array, 4, {{function|array_size}}(@array));
3 {{function|msg}}(@array);
{1, 2, 3, 4}
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)