Get first $n elements of a given array

array:get_head(ARRAY $array, INT $n=1) : ARRAY

# get the first element with its associated key
array:get_head(["foo", "bar", 3])
#=> [ "foo" ]

# geth the first 2 elements with their associated keys
array:get_head(["foo", "bar", 3], 2)
#=> [ "foo", "bar" ]

array:get_head([1,2,3],10)
#=> [ 1, 2, 3 ]

array:get_head([1,2,3],0)
#=> []

array:get_head(["foo"=>"bar","boo"=>"far"],1)
#=> [ "foo" => "bar" ]

Copyright ©2013-2022 SunSed®. All rights reserved.