<?xml version="1.0" encoding="utf-8"?>
<s1 title="Arrays"><p></p>
<s2 id="Arrays" title="Arrays">
<p>An array is used to store multiple values in a single variable. </p>
<p>Example array: </p>
<p></p>
<source><![CDATA[browser = ["Safari", "IE", "FireFox", "Chrome"]]]></source><p>the example given above shows an array with 4 elements (values), the elements are &quot;strings&quot;. Each element is seporated by commas: &quot;,&quot; </p>
<p>Arrays are indexed from 0, meaning the first elements index is 0, the second elements is 1 and so on. </p>
<p>An array element can be referenced separately, like so: </p>
<p></p>
<source><![CDATA[browser = ["Safari", "IE", "FireFox", "Chrome"]
echo browser[0]]]></source><p>The above example will return &quot;Safari&quot; as safari has an index of 0 within the &quot;browser&quot; Array. </p>
<p></p>
</s2>
<s2 id="Array Functions" title="Array Functions">
<p>The following functions can be used to manipulate an array. </p>
<p>Click each function name in the table below for more details of it, with examples. </p>
<table><strong class="highlight"><![CDATA[]]></strong><tr><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Function </strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Type</strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Description </strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p> </p>
</td><td><p> </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#p">push</jump> </p>
</td><td><p>int </p>
</td><td><p>Adds one or more elements to the end of an array and returns the new length of the array. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#p">pop</jump> </p>
</td><td><p>string </p>
</td><td><p>Removes the last element from an array and returns the value of that element. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#u">unshift</jump> </p>
</td><td><p>int </p>
</td><td><p>Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#s">shift</jump> </p>
</td><td><p>int </p>
</td><td><p>Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#c">concat</jump> </p>
</td><td><p>array </p>
</td><td><p>Used to join two or more arrays together. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#s">sort</jump> </p>
</td><td><p>array </p>
</td><td><p>Used to sort the order of array elements. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#j">join</jump> </p>
</td><td><p>string </p>
</td><td><p>Takes an array and joins the elements into one string. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#I">IndexOf</jump> </p>
</td><td><p>int </p>
</td><td><p>Checks for the first instance of an element and returns its position. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#l">lastIndexOf</jump> </p>
</td><td><p>int </p>
</td><td><p>Checks for the last instance of an element and returns its position. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#r">reverse</jump> </p>
</td><td><p>array </p>
</td><td><p>Reverses the order of the elements in the array. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#s">splice</jump> </p>
</td><td><p>array </p>
</td><td><p>Add or remove elements to or from an array, and return the removed elements. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#s">slice</jump> </p>
</td><td><p>array </p>
</td><td><p>Returns the selected elements in an array, as a new array object. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#l">length</jump> </p>
</td><td><p>int </p>
</td><td><p>Returns the length of an array. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#s">substr</jump> </p>
</td><td><p>String </p>
</td><td><p>This is used to return a section of a string </p>
</td></tr></table><p></p>
</s2>
<s2 id="Other" title="Other">
<table><strong class="highlight"><![CDATA[]]></strong><tr><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Name </strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Type</strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p><strong>Description </strong> </p>
</td><td><strong class="highlight"><![CDATA[]]></strong><p> </p>
</td><td><p> </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#M">Multi Dimensional</jump> </p>
</td><td><p>array </p>
</td><td><p>Allows multiple arrays within a single array. </p>
</td></tr><tr><td><p><jump href="/wiki/Arrays#A">Array Collections</jump> </p>
</td><td><p>array </p>
</td><td><p>An array consisting of JSON objects. </p>
</td></tr></table><p></p>
</s2>
<s2 id="push" title="push">
<p><strong>Usage:</strong> array.push(&quot;x&quot;) </p>
<p>Adds one or more elements to the end of an array and returns the new length of the array. </p>
<p><strong>Example:</strong> </p>
<ul><li>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>returnVal = myArray.push(&quot;e&quot;) </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>echo &quot;returnVal = &quot;+returnVal </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>myArray = a,b,c,d </li>
<li>myArray = a,b,c,d,e </li>
<li>returnVal = 5 </li>
</ul>
<p></p>
</s2>
<s2 id="pop" title="pop">
<p><strong>Usage:</strong> array.pop() </p>
<p>Removes the last element from an array and returns the value of that element. </p>
<p><strong>Example:</strong> </p>
<ul><li>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>returnVal = myArray.pop() </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>echo &quot;returnVal = &quot;+returnVal </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>myArray = a,b,c,d </li>
<li>myArray = a,b,c </li>
<li>returnVal = d </li>
</ul>
<p></p>
</s2>
<s2 id="unshift" title="unshift">
<p><strong>Usage:</strong> array.unshift(&quot;x&quot;) </p>
<p>Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1. </p>
<p><strong>Example:</strong> </p>
<ul><li>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>returnVal = myArray.unshift(&quot;_&quot;) </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>echo &quot;returnVal = &quot;+returnVal </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>a,b,c,d </li>
<li>_,a,b,c,d </li>
<li>5 </li>
</ul>
<p></p>
</s2>
<s2 id="shift" title="shift">
<p><strong>Usage:</strong> array.shift() </p>
<p>Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1. </p>
<p><strong>Example:</strong> </p>
<ul><li>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>returnVal = myArray.shift() </li>
<li>echo &quot;myArray = &quot;+myArray </li>
<li>echo &quot;returnVal = &quot;+returnVal </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>myArray = a,b,c,d </li>
<li>myArray = b,c,d </li>
<li>returnVal = a </li>
</ul>
<p></p>
</s2>
<s2 id="concat" title="concat">
<p><strong>Usage:</strong> array.concat() </p>
<p>used to join two or more arrays together. </p>
<p></p>
<s4 id="Example:" title="Example:">
<p>boy = [&quot;Luke&quot;, &quot;Bob&quot;,&quot;Jason&quot;] </p>
<p>girl = [&quot;Emma&quot;, &quot;Katie&quot;, &quot;Chiara&quot;] </p>
<p>uni = [&quot;Jordan&quot;,&quot;alex&quot;,&quot;Jessie&quot;] </p>
<p>names = uni.concat(girl,boy) </p>
<p>echo names </p>
<p></p>
</s4>
<s4 id="Result:" title="Result:">
<p>Jordan,alex,Jessie,Emma,Katie,Chiara,Luke,Bob,Jason </p>
<p></p>
</s4>
</s3>
</s2>
<s2 id="sort" title="sort">
<p><strong>Usage:</strong> array.sort() </p>
<p>Used to sort the order of array elements. </p>
<p><strong>Example:</strong> </p>
<ul><li>array = [&quot;b&quot;, &quot;a&quot;, &quot;d&quot;, &quot;c&quot;] </li>
<li>echo array.sort() </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>a,b,c,d </li>
</ul>
<p></p>
</s2>
<s2 id="join" title="join">
<p><strong>Usage:</strong> array.join() </p>
<p>Takes an array and joins the elements into one string. </p>
<p><strong>Example:</strong> </p>
<ul><li>array = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;] </li>
<li>echo array.join() </li>
</ul>
<p><strong>Result:</strong> </p>
<ul><li>&quot;a,b,c,d&quot; </li>
</ul>
<p></p>
</s2>
<s2 id="IndexOf" title="IndexOf">
<p><strong>Usage:</strong> array.indexOf() </p>
<p>Checks for the first instance of an element and returns its position. </p>
<p>If the item is not found, it will return as &quot;-1&quot; </p>
<p>If the item is present more than once, the indexOf method returns the position of the first occurrence. </p>
<p><strong>Example:</strong> </p>
<p>array = [&quot;google&quot;, &quot;yahoo&quot;, &quot;DuckDuckGo&quot;, &quot;Bing&quot;] </p>
<p>echo array.indexOf(&quot;DuckDuckGo&quot;) </p>
<p><strong>Result:</strong> </p>
<ul><li>2 </li>
</ul>
<p></p>
</s2>
<s2 id="lastIndexOf" title="lastIndexOf">
<p><strong>Usage:</strong> array.lastIndexOf() </p>
<p>Checks for the last instance of an element and returns its position. </p>
<p>If the item is not found, it will return as &quot;-1&quot; </p>
<p>If the item is present more than once, the lastIndexOf method returns the position of the last occurrence. </p>
<p><strong>Example:</strong> </p>
<p>array = [&quot;google&quot;, &quot;yahoo&quot;, &quot;DuckDuckGo&quot;, &quot;Bing&quot;,&quot;DuckDuckGo&quot;,&quot;google&quot;] </p>
<p>echo array.lastIndexOf(&quot;DuckDuckGo&quot;) </p>
<p><strong>Result:</strong> </p>
<ul><li>4 </li>
</ul>
<p></p>
</s2>
<s2 id="reverse" title="reverse">
<p><strong>Usage:</strong> array.reverse() </p>
<p>Reverses the order of the elements in the array. </p>
<p><strong>Example:</strong> </p>
<p>count = [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;] </p>
<p>echo count.reverse() </p>
<p><strong>Result:</strong> </p>
<ul><li>5,4,3,2,1 </li>
</ul>
<p></p>
</s2>
<s2 id="splice" title="splice">
<p><strong>Usage:</strong> array.splice() </p>
<p>adds or removes elements to or from an array, and returns the removed elements. </p>
<p><strong>Example:</strong> </p>
<p>browser = [&quot;Safari&quot;, &quot;IE&quot;, &quot;FireFox&quot;, &quot;Chrome&quot;] </p>
<p>echo browser.splice(2, 2) </p>
<p><strong>Result:</strong> </p>
<ul><li><p>FireFox,chrome </p>
</li>
<li>Safari,IE </li>
</ul>
<p></p>
</s2>
<s2 id="slice" title="slice">
<p><strong>Usage:</strong> array.slice() </p>
<p>The slice() method returns the selected elements in an array, as a new array object. </p>
<p>The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. </p>
<p><strong>Example:</strong> </p>
<p>browsers = [&quot;IE&quot;, &quot;Chrome&quot;, &quot;FireFox&quot;, &quot;Safari&quot;, &quot;SeaMonkey&quot;] </p>
<p>Good = browsers.slice(1, 3) </p>
<p><strong>Result:</strong> </p>
<ul><li><p>Good = Chrome,FireFox </p>
</li>
</ul>
<p></p>
</s2>
<s2 id="length" title="length">
<p><strong>Usage:</strong> array.length </p>
<p>Returns the length of an array as an integer. </p>
<p><strong>Example:</strong> </p>
<p>array = SearchEnemyCastles(10) echo &quot;length: &quot; + array.length + &quot;, id: &quot; + array[0].id + &quot;, CityName: &quot; + array[0].name + &quot;, userName: &quot; + array[0].userName + &quot;, alliance: &quot; + array[0].allianceName + &quot;, prestige: &quot; + array[0].prestige + &quot;, honor: &quot; + array[0].honor </p>
<p><strong>Result:</strong> </p>
<ul><li><p>length: 19, id: 17894, CityName: RED, userName: SomeN00b, alliance: 422, prestige: 6758, honor: 10495584936 </p>
</li>
</ul>
<p></p>
</s2>
<s2 id="Multi Dimensional" title="Multi Dimensional">
<p><strong>Usage:</strong> array = [1,[&quot;a1&quot;,&quot;a2&quot;,&quot;a3&quot;],[&quot;b1&quot;,&quot;b2&quot;,&quot;b3&quot;],2] </p>
<p><strong>Example:</strong> </p>
<p>array = [&quot;bob&quot;,[&quot;count&quot;,1,2,3],[&quot;letters&quot;,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;],&quot;bill&quot;] </p>
<p>echo array[1][0]+&quot; The amount of &quot;+array[2][0]&quot;in this array.&quot; </p>
<p>echo array[1][1]+&quot;. &quot;+array[1][1] </p>
<p>echo array[1][2]+&quot;. &quot;+array[1][2] </p>
<p>echo array[1][3]+&quot;. &quot;+array[1][3] </p>
<p>echo array[0]+&quot; &amp; &quot;+array[3]+&quot; have been added to the main array also.&quot; </p>
<p><strong>Result:</strong> </p>
<ul><li>- count The amount of letters in this array. </li>
<li>- 1. a </li>
<li>- 2. b </li>
<li>- 3. c </li>
<li><p>- bob &amp; bill have been added to the main array also. </p>
</li>
</ul>
<p></p>
</s2>
<s2 id="Array Collections" title="Array Collections">
<p>This method allows you to define <jump href="/wiki/JSON#J">JSON objects</jump> within an array. </p>
<p><strong>Usage:</strong> array = [ {a:1},{b:2} ] </p>
<p><strong>Example:</strong> </p>
<p>array = [ {a:1},{b:2} ] </p>
<p>echo array[0].a </p>
<p>echo array[1].b </p>
<p><strong>Result:</strong> </p>
<ul><li>- 1 </li>
<li>- 2 </li>
</ul>
<p></p>
</s2>
<s2 id="substr" title="substr">
<p>Returns a select section of a string. </p>
<p>options are required in the substr brackets &quot;substr(options)&quot; </p>
<p><strong>Usage:</strong> string.substr() </p>
<p>In the Example below the options are &quot;0, 4&quot; this will start the new string at char &quot;0&quot; of the existing string, and end it 4 chars after. </p>
<p><strong>Example:</strong> theString = &quot;NEAT Bot&quot; </p>
<p>echo theString.substr(0, 4) </p>
<p><strong>Result:</strong> </p>
<ul><li>NEAT </li>
</ul>
<p></p>

<br/>------------------------------------------------------------------------------<br/>
<p> <jump href="/wiki/CategoryFunctions">CategoryFunctions</jump> </p>
</s2></s1>