array_shift_right()array_shift_right()

array_shift_right() 将数组中的值向右移动。array_shift_right() shifts values inside an array to the right.

语法Syntax

array_shift_right(arr , shift_count [, fill_value ])array_shift_right(arr, shift_count [, fill_value ])

参数Arguments

  • arr :要拆分的输入数组,必须是动态数组。arr: Input array to split, must be dynamic array.
  • shift_count :整数,用于指定数组元素将向右移动的位置数。shift_count: Integer specifying the number of positions that array elements will be shifted to the right. 如果该值为负数,则元素将向左移动。If the value is negative, the elements will be shifted to the left.
  • fill_value :用于插入元素的标量值,而不是移动和删除的元素。fill_value: scalar value that is used for inserting elements instead of the ones that were shifted and removed. 默认值:null 值或空字符串(取决于 arr 类型)。Default: null value or empty string (depending on the arr type).

返回Returns

包含与原始数组相同元素数的动态数组。Dynamic array containing the same amount of the elements as in the original array. 每个元素均已根据 shift_count 进行了移动。Each element has been shifted according to shift_count. 添加的新元素(而不是删除的元素)将包含值 fill_valueNew elements that are added instead of the removed elements will have a value of fill_value.

另请参阅See also

示例Examples

  • 向右移动两个位置:Shifting to the right by two positions:

    print arr=dynamic([1,2,3,4,5]) 
    | extend arr_shift=array_shift_right(arr, 2)
    
    arrarr arr_shiftarr_shift
    [1,2,3,4,5][1,2,3,4,5] [null,null,1,2,3][null,null,1,2,3]
  • 向右移动两个位置并添加默认值:Shifting to the right by two positions and adding a default value:

    print arr=dynamic([1,2,3,4,5]) 
    | extend arr_shift=array_shift_right(arr, 2, -1)
    
    arrarr arr_shiftarr_shift
    [1,2,3,4,5][1,2,3,4,5] [-1,-1,1,2,3][-1,-1,1,2,3]
  • 使用负 shift_count 值向左移动两个位置:Shifting to the left by two positions by using a negative shift_count value:

    print arr=dynamic([1,2,3,4,5]) 
    | extend arr_shift=array_shift_right(arr, -2, -1)
    
    arrarr arr_shiftarr_shift
    [1,2,3,4,5][1,2,3,4,5] [3,4,5,-1,-1][3,4,5,-1,-1]