Unset all array elements past certain element in PHP

$example = array('First','Second','Third','Fourth','Fifth',...

The code below will unset the third element in $example.

unset($example[2]);

How can I unset all of the elements past the third element?

I want $example's value to be this afterwards:

$example = array('First','Second','Third');

Answers


Don't use unset, use array_splice:

$example = array('First','Second','Third','Fourth','Fifth');
array_splice($example,3);
//$example = array('First','Second','Third');

Need Your Help

How can I get git to follow symlinks?

git symlink

I've had a google for how to do this, but not had any luck.

How to run Eclipse Project using Escripts plugin?

java eclipse eclipse-plugin jdt escript

I have installed Eclipse Escripts plugin, but it does not seem to have proper documentation and I am very new to Eclipse JDT API.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.