Jump to content

[SOLVED] array_pop


mtylerb

Recommended Posts

Is there something that is more efficient than array_pop?  I'm currently using it like:

 

<?php
private function trimc($limit)
{
	while (count($this->children) != $limit)
	{
		array_pop($this->children);
	}
}
?>

 

The code is used to trim the end results off an array which is the result of multiple arrays being combined together and sorted.  My method seems rather inefficient and was the only way that I could think of doing it.  The array that I'm wanting to trim is an array of PageArchive Objects.

Link to comment
Share on other sites

So, something like:

 

<?php

private function trimc($limit)
{
	array_slice($this->children, 0, $limit);
}

?>

 

Would be more efficient?  Does this automatically rewrite the array or do I need to save it back into the variable?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.