如何获取第一个到倒数第二个数组元素的范围?
例如,
$array = 1,2,3,4,5
$array[0] - will give me the first (1)
$array[-2] - will give me the second last (4)
$array[0..2] - will give me first to third (1,2,3)
$array[0..-2] - I'm expecting to get first to second last (1,2,3,4) but I get 1,5,4 ???
我知道我可以手写并使用for($x=0;$x -lt $array.count;$x++)
,但我正在寻找方括号的快捷方式。
$array[0..($array.length-2)]
来实现相同的功能。 - Robert Westerlund