-1

I have this code:

$hackers = array ('Alan Kay', 'Peter Norvig', 'Linus Trovalds', 'Larry Page');

I want to delete 1st two items and later want to get back just deleted items in an array

1 Answers1

3

Use array_splice(). It returns an array of the elements that it removed:

$first_two = array_splice($hackers, 0, 2);
Barmar
  • 741,623
  • 53
  • 500
  • 612