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.)
== associative_array ==
Copy Code
The output would be:
Copy Code
The output would be:
Works exactly like array(), except the array created will be an associative array, even if the array has been created with no elements. This is the only use case where this is necessary, vs using the normal array() function, or in the case where you assign sequential keys anyways, and the same array could have been created using array().
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| associative_array
|-
! scope="row" | Returns
| array
|-
! scope="row" | Usages
| [args...]
|-
! scope="row" | Throws
|
|-
! scope="row" | Since
| 3.3.1
|-
! scope="row" | Restricted
| No
|-
! scope="row" | Optimizations
| None
|}
=== Usages ===
associative_array([args...])=== Examples === ====Example 1==== Usage with an empty array Given the following code:
assign(@array, associative_array())
msg(is_associative(@array))

1 {{function|assign}}(@array, {{function|associative_array}}())
2 {{function|msg}}({{function|is_associative}}(@array))
true====Example 2==== Usage with an array with sequential keys Given the following code:
assign(@array, array(0: '0', 1: '1'))
msg(is_associative(@array))
assign(@array, associative_array(0: '0', 1: '1'))
msg(is_associative(@array))

1 {{function|assign}}(@array, {{function|array}}(0: '0', 1: '1'))
2 {{function|msg}}({{function|is_associative}}(@array))
3 {{function|assign}}(@array, {{function|associative_array}}(0: '0', 1: '1'))
4 {{function|msg}}({{function|is_associative}}(@array))
true true===See Also=== [[Arrays|Learning Trail: Arrays]], [[Array_Iteration|Learning Trail: Array Iteration]]
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.)