2017-08-06 16:24:47 +02:00
{
2017-08-09 16:34:20 +02:00
"name": "array_slice",
2017-08-06 16:24:47 +02:00
"type": "function",
2020-07-02 01:46:48 +01:00
"groups": ["Arrays"],
2017-08-06 16:55:40 +02:00
"description": "Returns a portion of the array. The slice is defined by the start_pos and end_pos arguments.",
2017-08-06 16:24:47 +02:00
"arguments": [{
"arg": "array",
"description": "an array"
},
{
2017-08-06 16:55:40 +02:00
"arg": "start_pos",
"description": "the index of the start position of the slice (0 based). The start_pos index is included in the slice. If you use a negative start_pos, the index is counted from the end of the list (-1 based)."
2017-08-06 16:24:47 +02:00
},
{
2017-08-06 16:55:40 +02:00
"arg": "end_pos",
"description": "the index of the end position of the slice (0 based). The end_pos index is included in the slice. If you use a negative end_pos, the index is counted from the end of the list (-1 based)."
2017-08-06 16:24:47 +02:00
}
],
"examples": [{
"expression": "array_slice(array(1,2,3,4,5),0,3)",
2018-08-24 14:04:27 +02:00
"returns": "[ 1, 2, 3, 4 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array(1,2,3,4,5),0,-1)",
2018-08-24 14:04:27 +02:00
"returns": "[ 1, 2, 3, 4, 5 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array(1,2,3,4,5),-5,-1)",
2018-08-24 14:04:27 +02:00
"returns": "[ 1, 2, 3, 4, 5 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array(1,2,3,4,5),0,0)",
2018-08-24 14:04:27 +02:00
"returns": "[ 1 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array(1,2,3,4,5),-2,-1)",
2018-08-24 14:04:27 +02:00
"returns": "[ 4, 5 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array(1,2,3,4,5),-1,-1)",
2018-08-24 14:04:27 +02:00
"returns": "[ 5 ]"
2017-08-06 16:24:47 +02:00
},
{
"expression": "array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),1,2)",
2018-08-24 14:04:27 +02:00
"returns": "[ 'Valmiera', 'Chugiak' ]"
2017-08-06 16:24:47 +02:00
},
{
2020-10-14 07:06:37 +02:00
"expression": "array_slice(array('Dufour','Valmiera','Chugiak','Brighton'),-2,-1)",
2018-08-24 14:04:27 +02:00
"returns": "[ 'Chugiak', 'Brighton' ]"
2017-08-06 16:24:47 +02:00
}
]
}