tags:

views:

46

answers:

3

What is the best way to accomplish this?

+1  A: 

In the current order? I'd say array_slice(). Since it's a built in function it will be faster than looping through the array while keeping track of an incrementing index until N.

Fanis
+5  A: 

Using array_slice (see doc)

Taken from the examples of the documentation

$input = array("a", "b", "c", "d", "e");
$output = array_slice($input, 0, 3);   // returns "a", "b", and "c"
corbacho
+1  A: 

You can use array_slice as:

$sliced_array = array_slice($array,0,$N);
codaddict