<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>Arrays</title><revhistory><revision><revnumber>25</revnumber><date>2015-04-17 00:19:57</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>24</revnumber><date>2015-04-17 00:17:06</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>23</revnumber><date>2015-04-17 00:03:06</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>22</revnumber><date>2014-11-23 18:20:31</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>21</revnumber><date>2014-11-23 18:17:50</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>20</revnumber><date>2014-11-23 17:00:54</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>19</revnumber><date>2014-10-22 23:20:07</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>18</revnumber><date>2014-08-27 17:03:30</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>17</revnumber><date>2014-08-03 14:13:51</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>16</revnumber><date>2014-08-03 12:44:56</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>15</revnumber><date>2014-08-03 12:42:43</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>14</revnumber><date>2014-08-03 12:41:30</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>13</revnumber><date>2014-07-30 20:09:18</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>12</revnumber><date>2014-07-29 06:04:32</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>11</revnumber><date>2014-07-29 05:37:03</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>10</revnumber><date>2014-07-29 05:10:09</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>9</revnumber><date>2014-07-29 04:59:28</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>8</revnumber><date>2014-07-29 04:47:54</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>7</revnumber><date>2014-07-29 04:27:17</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>6</revnumber><date>2014-07-29 03:53:51</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>5</revnumber><date>2014-07-28 23:26:53</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>4</revnumber><date>2014-07-28 23:25:16</date><authorinitials>LKD70</authorinitials></revision><revision><revnumber>3</revnumber><date>2014-01-27 11:41:28</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>2</revnumber><date>2014-01-27 11:41:06</date><authorinitials>Inanna</authorinitials></revision><revision><revnumber>1</revnumber><date>2014-01-27 11:40:41</date><authorinitials>Inanna</authorinitials></revision></revhistory></articleinfo><section><title>Arrays</title><para>An array is used to store multiple values in a single variable. </para><para>Example array: </para><screen><![CDATA[browser = ["Safari", "IE", "FireFox", "Chrome"]]]></screen><para>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; </para><para>Arrays are indexed from 0, meaning the first elements index is 0, the second elements is 1 and so on. </para><para>An array element can be referenced separately, like so: </para><screen><![CDATA[browser = ["Safari", "IE", "FireFox", "Chrome"]
echo browser[0]]]></screen><para>The above example will return &quot;Safari&quot; as safari has an index of 0 within the &quot;browser&quot; Array. </para></section><section><title>Array Functions</title><para>The following functions can be used to manipulate an array. </para><para>Click each function name in the table below for more details of it, with examples. </para><informaltable><tgroup cols="6"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><colspec colname="col_3"/><colspec colname="col_4"/><colspec colname="col_5"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para><emphasis role="strong">Function </emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Type</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Description </emphasis> </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"/><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="push">push</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>Adds one or more elements to the end of an array and returns the new length of the array. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="pop">pop</link> </para></entry><entry colsep="1" rowsep="1"><para>string </para></entry><entry colsep="1" rowsep="1"><para>Removes the last element from an array and returns the value of that element. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="unshift">unshift</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>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. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="shift">shift</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>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. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="concat">concat</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Used to join two or more arrays together. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="sort">sort</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Used to sort the order of array elements. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="join">join</link> </para></entry><entry colsep="1" rowsep="1"><para>string </para></entry><entry colsep="1" rowsep="1"><para>Takes an array and joins the elements into one string. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="IndexOf">IndexOf</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>Checks for the first instance of an element and returns its position. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="lastIndexOf">lastIndexOf</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>Checks for the last instance of an element and returns its position. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="reverse">reverse</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Reverses the order of the elements in the array. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="splice">splice</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Add or remove elements to or from an array, and return the removed elements. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="slice">slice</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Returns the selected elements in an array, as a new array object. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="length">length</link> </para></entry><entry colsep="1" rowsep="1"><para>int </para></entry><entry colsep="1" rowsep="1"><para>Returns the length of an array. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="substr">substr</link> </para></entry><entry colsep="1" rowsep="1"><para>String </para></entry><entry colsep="1" rowsep="1"><para>This is used to return a section of a string </para></entry></row></tbody></tgroup></informaltable></section><section><title>Other</title><informaltable><tgroup cols="6"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><colspec colname="col_3"/><colspec colname="col_4"/><colspec colname="col_5"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para><emphasis role="strong">Name </emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Type</emphasis> </para></entry><entry colsep="1" rowsep="1"><para><emphasis role="strong">Description </emphasis> </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"/><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="Multi Dimensional">Multi Dimensional</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>Allows multiple arrays within a single array. </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para><link linkend="Array Collections">Array Collections</link> </para></entry><entry colsep="1" rowsep="1"><para>array </para></entry><entry colsep="1" rowsep="1"><para>An array consisting of JSON objects. </para></entry></row></tbody></tgroup></informaltable></section><section><title>push</title><para><emphasis role="strong">Usage:</emphasis> array.push(&quot;x&quot;) </para><para>Adds one or more elements to the end of an array and returns the new length of the array. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>returnVal = myArray.push(&quot;e&quot;) </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>echo &quot;returnVal = &quot;+returnVal </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = a,b,c,d </para></listitem><listitem override="none"><para>myArray = a,b,c,d,e </para></listitem><listitem override="none"><para>returnVal = 5 </para></listitem></itemizedlist></section><section><title>pop</title><para><emphasis role="strong">Usage:</emphasis> array.pop() </para><para>Removes the last element from an array and returns the value of that element. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>returnVal = myArray.pop() </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>echo &quot;returnVal = &quot;+returnVal </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = a,b,c,d </para></listitem><listitem override="none"><para>myArray = a,b,c </para></listitem><listitem override="none"><para>returnVal = d </para></listitem></itemizedlist></section><section><title>unshift</title><para><emphasis role="strong">Usage:</emphasis> array.unshift(&quot;x&quot;) </para><para>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. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>returnVal = myArray.unshift(&quot;_&quot;) </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>echo &quot;returnVal = &quot;+returnVal </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>a,b,c,d </para></listitem><listitem override="none"><para>_,a,b,c,d </para></listitem><listitem override="none"><para>5 </para></listitem></itemizedlist></section><section><title>shift</title><para><emphasis role="strong">Usage:</emphasis> array.shift() </para><para>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. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;] </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>returnVal = myArray.shift() </para></listitem><listitem override="none"><para>echo &quot;myArray = &quot;+myArray </para></listitem><listitem override="none"><para>echo &quot;returnVal = &quot;+returnVal </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>myArray = a,b,c,d </para></listitem><listitem override="none"><para>myArray = b,c,d </para></listitem><listitem override="none"><para>returnVal = a </para></listitem></itemizedlist></section><section><title>concat</title><para><emphasis role="strong">Usage:</emphasis> array.concat() </para><para>used to join two or more arrays together. </para><section><title>Example:</title><para>boy = [&quot;Luke&quot;, &quot;Bob&quot;,&quot;Jason&quot;] </para><para>girl = [&quot;Emma&quot;, &quot;Katie&quot;, &quot;Chiara&quot;] </para><para>uni = [&quot;Jordan&quot;,&quot;alex&quot;,&quot;Jessie&quot;] </para><para>names = uni.concat(girl,boy) </para><para>echo names </para></section><section><title>Result:</title><para>Jordan,alex,Jessie,Emma,Katie,Chiara,Luke,Bob,Jason </para></section></section><section><title>sort</title><para><emphasis role="strong">Usage:</emphasis> array.sort() </para><para>Used to sort the order of array elements. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>array = [&quot;b&quot;, &quot;a&quot;, &quot;d&quot;, &quot;c&quot;] </para></listitem><listitem override="none"><para>echo array.sort() </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>a,b,c,d </para></listitem></itemizedlist></section><section><title>join</title><para><emphasis role="strong">Usage:</emphasis> array.join() </para><para>Takes an array and joins the elements into one string. </para><para><emphasis role="strong">Example:</emphasis> </para><itemizedlist><listitem override="none"><para>array = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;] </para></listitem><listitem override="none"><para>echo array.join() </para></listitem></itemizedlist><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>&quot;a,b,c,d&quot; </para></listitem></itemizedlist></section><section><title>IndexOf</title><para><emphasis role="strong">Usage:</emphasis> array.indexOf() </para><para>Checks for the first instance of an element and returns its position. </para><para>If the item is not found, it will return as &quot;-1&quot; </para><para>If the item is present more than once, the indexOf method returns the position of the first occurrence. </para><para><emphasis role="strong">Example:</emphasis> </para><para>array = [&quot;google&quot;, &quot;yahoo&quot;, &quot;DuckDuckGo&quot;, &quot;Bing&quot;] </para><para>echo array.indexOf(&quot;DuckDuckGo&quot;) </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>2 </para></listitem></itemizedlist></section><section><title>lastIndexOf</title><para><emphasis role="strong">Usage:</emphasis> array.lastIndexOf() </para><para>Checks for the last instance of an element and returns its position. </para><para>If the item is not found, it will return as &quot;-1&quot; </para><para>If the item is present more than once, the lastIndexOf method returns the position of the last occurrence. </para><para><emphasis role="strong">Example:</emphasis> </para><para>array = [&quot;google&quot;, &quot;yahoo&quot;, &quot;DuckDuckGo&quot;, &quot;Bing&quot;,&quot;DuckDuckGo&quot;,&quot;google&quot;] </para><para>echo array.lastIndexOf(&quot;DuckDuckGo&quot;) </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>4 </para></listitem></itemizedlist></section><section><title>reverse</title><para><emphasis role="strong">Usage:</emphasis> array.reverse() </para><para>Reverses the order of the elements in the array. </para><para><emphasis role="strong">Example:</emphasis> </para><para>count = [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;] </para><para>echo count.reverse() </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>5,4,3,2,1 </para></listitem></itemizedlist></section><section><title>splice</title><para><emphasis role="strong">Usage:</emphasis> array.splice() </para><para>adds or removes elements to or from an array, and returns the removed elements. </para><para><emphasis role="strong">Example:</emphasis> </para><para>browser = [&quot;Safari&quot;, &quot;IE&quot;, &quot;FireFox&quot;, &quot;Chrome&quot;] </para><para>echo browser.splice(2, 2) </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>FireFox,chrome </para></listitem><listitem override="none"><para>Safari,IE </para></listitem></itemizedlist></section><section><title>slice</title><para><emphasis role="strong">Usage:</emphasis> array.slice() </para><para>The slice() method returns the selected elements in an array, as a new array object. </para><para>The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. </para><para><emphasis role="strong">Example:</emphasis> </para><para>browsers = [&quot;IE&quot;, &quot;Chrome&quot;, &quot;FireFox&quot;, &quot;Safari&quot;, &quot;SeaMonkey&quot;] </para><para>Good = browsers.slice(1, 3) </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>Good = Chrome,FireFox </para></listitem></itemizedlist></section><section><title>length</title><para><emphasis role="strong">Usage:</emphasis> array.length </para><para>Returns the length of an array as an integer. </para><para><emphasis role="strong">Example:</emphasis> </para><para>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 </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>length: 19, id: 17894, CityName: RED, userName: SomeN00b, alliance: 422, prestige: 6758, honor: 10495584936 </para></listitem></itemizedlist></section><section><title>Multi Dimensional</title><para><emphasis role="strong">Usage:</emphasis> array = [1,[&quot;a1&quot;,&quot;a2&quot;,&quot;a3&quot;],[&quot;b1&quot;,&quot;b2&quot;,&quot;b3&quot;],2] </para><para><emphasis role="strong">Example:</emphasis> </para><para>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;] </para><para>echo array[1][0]+&quot; The amount of &quot;+array[2][0]&quot;in this array.&quot; </para><para>echo array[1][1]+&quot;. &quot;+array[1][1] </para><para>echo array[1][2]+&quot;. &quot;+array[1][2] </para><para>echo array[1][3]+&quot;. &quot;+array[1][3] </para><para>echo array[0]+&quot; &amp; &quot;+array[3]+&quot; have been added to the main array also.&quot; </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>- count The amount of letters in this array. </para></listitem><listitem override="none"><para>- 1. a </para></listitem><listitem override="none"><para>- 2. b </para></listitem><listitem override="none"><para>- 3. c </para></listitem><listitem override="none"><para>- bob &amp; bill have been added to the main array also. </para></listitem></itemizedlist></section><section><title>Array Collections</title><para>This method allows you to define <ulink url="http://guide.neatportal.com/wiki/Arrays/wiki/JSON#JSON_Object">JSON objects</ulink> within an array. </para><para><emphasis role="strong">Usage:</emphasis> array = [ {a:1},{b:2} ] </para><para><emphasis role="strong">Example:</emphasis> </para><para>array = [ {a:1},{b:2} ] </para><para>echo array[0].a </para><para>echo array[1].b </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>- 1 </para></listitem><listitem override="none"><para>- 2 </para></listitem></itemizedlist></section><section><title>substr</title><para>Returns a select section of a string. </para><para>options are required in the substr brackets &quot;substr(options)&quot; </para><para><emphasis role="strong">Usage:</emphasis> string.substr() </para><para>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. </para><para><emphasis role="strong">Example:</emphasis> theString = &quot;NEAT Bot&quot; </para><para>echo theString.substr(0, 4) </para><para><emphasis role="strong">Result:</emphasis> </para><itemizedlist><listitem override="none"><para>NEAT </para></listitem></itemizedlist><!--rule (<hr>) is not applicable to DocBook--><para> <ulink url="http://guide.neatportal.com/wiki/Arrays/wiki/CategoryFunctions#">CategoryFunctions</ulink> </para></section></article>